I am working with multi-dimensional Numpy arrays. I have noticed some inconsistent behavior when accessing these arrays with other index arrays. For example:
import numpy as np
start = np.zeros((7,5,3))
a = start[:,:,np.arange(2)]
b = start[0,:,np.arange(2)]
c = start[0,:,:2]
print 'a:', a.shape
print 'b:', b.shape
print 'c:', c.shape
In this example, I get the result:
a: (7, 5, 2)
b: (2, 5)
c: (5, 2)
This confuses me. Why do "b" and "c" not have the same dimensions? Why does "b" swap the axis order, but not "a"?
I have been able to design my code around these inconsistencies thanks to lots of unit tests, but understanding what is going on would be appreciated.
For reference, I am using Python 2.7.3, and Numpy 1.6.2 via MacPorts.