Implicit Transposing In Numpy Array Indexing
I came across a weird problem: from numpy import zeros, arange aa = zeros([1, 3, 10]) aa[0, :, arange(5)].shape Running this gives me (5,3), but I'm expecting (3,5). However, runn
Solution 1:
This is a case of mixed basic and advanced indexing. The 1st and last indexes are numeric, and the middle a slice. It selects values based the 0
and arange(5)
, and appends the :
dimension at the end.
aa[0, :, :5].shape
should produce the (3,5) you expect.
http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#combining-advanced-and-basic-indexing
Numpy 3D array transposed when indexed in single step vs two steps contrasts the behavior of
y = x[0, :, mask]
z = x[0, :, :][:, mask]
Be sure to check the comments to my answer, for the argument that this is a bug and will be fixed.
Post a Comment for "Implicit Transposing In Numpy Array Indexing"