[Numpy-discussion] Fancy indexing oddity
Bradley M. Froehle
brad.froehle at gmail.com
Tue Jul 2 23:44:19 EDT 2013
A colleague just showed me this indexing behavior and I was at a loss
to explain what was going on. Can anybody else chime in and help me
understand this indexing behavior?
>>> import numpy as np
>>> np.__version__
'1.7.1'
>>> A = np.ones((2,3,5))
>>> mask = np.array([True]*4 + [False], dtype=bool)
>>> A.shape
(2, 3, 5)
>>> A[:,:,mask].shape
(2, 3, 4)
>>> A[:,1,mask].shape
(2, 4)
>>> A[1,:,mask].shape
(4, 3) # Why is this not (3, 4)?
>>> A[1][:,mask].shape
(3, 4)
Thanks!
Brad
More information about the NumPy-Discussion
mailing list