Suppose there we have an array of shape(10, 20, 30).
What I would like to get are all the:
- 20*30 arrays of shape(10),
- 10*30 arrays of shape(20),
- 10*20 arrays of shape(30).
Locking all dimensions but one manually is easy, but I am struggling to write an efficient loop to iterate this way. The reason for this is that in my application case, I will have several dimensions which will vary between 2 to 5, and I will need to get all subarrays of locking all dimensions but one.
I thought I could use transpose and roll to create an index which rolls, such as
data = np.zeros((10, 20, 30))
for ndim in range(len(data.shape)):
index = np.arange(0, len(data.shape)), 1)
index = np.roll(index, 1)
_data = np.transpose(data, index)[0]
... and then I realized this is useless, because its the opposite of what I need.
I got to the point I even tried asking chatgpt. So it's time to ask for help. I am utterly stuck