Numpy slicing/indexing changes order of axis

46 views Asked by At

I was working on a code and noticed that numpy indexing and slicing doesn't work as I expected. For example,

x = np.random.randn(1,5,3,4)
y = x[0, :, :, [1,2]]
y.shape

I expected y.shape to be (5,3,2) but instead got (2,5,3). Does anyone know why the expected third axis is moved to the first axis?

0

There are 0 answers