[Numpy-discussion] Numpy array slicing
Eirik Gjerløw
eirik.gjerlow@astro.uio...
Thu Feb 9 07:28:12 CST 2012
Ok, that was an enlightening discussion, I guess I signed up for this
list a couple of days too late!
Thanks,
Eirik
On 09. feb. 2012 12:55, Olivier Delalleau wrote:
> This was actually discussed very recently (for more details:
> http://mail.scipy.org/pipermail/numpy-discussion/2012-February/060232.html).
>
> It's caused by mixing slicing with advanced indexing. The resulting
> shape is the concatenation of a first part obtained by broadcasting of
> the non-slice items (in your case, 0 and mask[0] being broadcasted to
> shape (12285,), the number of non-zero elements in mask[0]), followed
> by a second part obtained by the slice items (in your case extracting
> dimensions #1 and #3 of a, i.e. shape (4, 2)).
> So the final shape is (12285, 4, 2).
>
> -=- Olivier
>
>
> Le 9 février 2012 06:32, Eirik Gjerløw <eirik.gjerlow@astro.uio.no
> <mailto:eirik.gjerlow@astro.uio.no>> a écrit :
>
> Hello,
>
> (also sent to Scipy-User, sorry for duplicates).
>
> This is (I think) a rather basic question about numpy slicing. I have
> the following code:
>
> In [29]: a.shape
> Out[29]: (3, 4, 12288, 2)
>
> In [30]: mask.shape
> Out[30]: (3, 12288)
>
> In [31]: mask.dtype
> Out[31]: dtype('bool')
>
> In [32]: sum(mask[0])
> Out[32]: 12285
>
> In [33]: a[[0] + [slice(None)] + [mask[0]] + [slice(None)]].shape
> Out[33]: (12285, 4, 2)
>
> My question is: Why is not the final shape (4, 12285, 2) instead of
> (12285, 4, 2)?
>
> Eirik Gjerløw
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org <mailto:NumPy-Discussion@scipy.org>
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120209/8ce12e9b/attachment-0001.html
More information about the NumPy-Discussion
mailing list