The problem
Create a higher dimensional NumPy array with zeros on the new dimensions
Details
Analyzing the last dimension, the result is similar to this:
(not an actual code, just a didactic example)
a.shape = (100,2,10)
a[0,0,0]=1
a[0,0,1]=2
...
a[0,0,9]=10
b.shape = (100,2,10,10)
b[0,0,0,:]=[0,0,0,0,0,0,0,0,0,1]
b[0,0,1,:]=[0,0,0,0,0,0,0,0,2,1]
b[0,0,2,:]=[0,0,0,0,0,0,0,3,2,1]
...
b[0,0,2,:]=[10,9,8,7,6,5,4,3,2,1]
a -> b
The objective is to transform from a into b. The problem is that is not only filled with zeros but has a sequential composition with the original array.
Simpler problem for better understanding
Another way to visualize is using lower-dimensional arrays:
We have this:
a = [1,2]
And I want this:
b = [[0,1],[2,1]]
Using NumPy array and avoiding long for loops.
2d to 3d case
We have this:
a = [[1,2,3],[4,5,6],[7,8,9]]
And I want this:
b[0] = [[0,0,1],[0,2,1],[3,2,1]]
b[1] = [[0,0,4],[0,5,4],[6,5,4]]
b[2] = [[0,0,7],[0,8,7],[9,8,7]]
I feel that for the 4-dimensional problem only one for loop with 10 iterations is enough.
bare a squat array and you can achieve your result with a triangular matrix. When you saya = [1, 2], do you mean that you want each row ofbto count down from each element ofadown to 0 and then remain 0 for any leftover elements in the row? Is that 1-2 sequential? Could you havea = [1, 3, 2]?a=[1,3,2]but than we would haveb = [[0,0,1],[0,1,3],[1,3,2]]. I don't see how to do with a triangular matrix. What I was trying is to append and delete elements and add to a new np.zeros array with more dimensions.