[Relay]What does relay.take() mean? Is it a copy or a reference?

For arr[i][j] = 1 just do relay.ones instead of relay.zeros

For arr[i][j] += 1 use scatter_add.

Scatter_add:

  output[indices[i][j]][j] += updates[i][j] if axis = 0,
  output[i][indices[i][j]] += updates[i][j] if axis = 1,

If scatter_add is insufficient, then you will need to use scatter_nd with ‘add’ mode.

The scatter_nd is pretty complicated but a few examples and you should know what is going on. It is pretty standard operator in Deep Learning. Here is an example: https://github.com/onnx/onnx/blob/master/docs/Operators.md#scatternd