I'm given an array with an arbitrary number of axes, and I want to iterate over, say the first 'd' of them. How do I do this?
Initially I thought I would make an array containing all the indices I want to loop through, using
i = np.indices(a.shape[:d])
indices = np.transpose(np.asarray([x.flatten() for x in i]))
for idx in indices:
a[idx]
But apparently I cannot index an array like that, i.e. using another array containing the index.