I have a numpy ndarray, let's take an example (but it can be totally different):
[[[0 0 0]
[1 1 1]
[0 0 0]]
[[1 0 1]
[1 0 1]
[1 0 1]]]
[[1 0 0]
[1 1 0]
[1 1 1]]]
I want to add to each element the sum of its indexes in all dimensions. The result here would be:
[[[ 0 1 2]
[ 4 5 6]
[ 6 7 8]]
[[10 10 12]
[13 13 15]
[16 16 18]]
[[19 19 20]
[22 23 23]
[25 26 27]]]
To do so, I built another ndarray:
shp = a.shape
b = np.arange(shp[0]**len(shp)).reshape(shp)
And I got my result:
result = a+b
I would like to know if there is a more direct solution, which wouldn't need the creation of this second ndarray, a way to do the same operation 'on location' ??