[Numpy-discussion] Indexing bug?

Jaime Fernández del Río jaime.frio@gmail....
Sat Mar 30 13:13:35 CDT 2013


On Sat, Mar 30, 2013 at 11:01 AM, Ivan Oseledets
<ivan.oseledets@gmail.com>wrote:

> I am using numpy 1.6.1,
> and encountered a wierd fancy indexing bug:
>
> import numpy as np
> c = np.random.randn(10,200,10);
>
> In [29]: print c[[0,1],:200,:2].shape
> (2, 200, 2)
>
> In [30]: print c[[0,1],:200,[0,1]].shape
> (2, 200)
>
> It means, that here fancy indexing is not working right for a 3d array.
>

It is working fine, review the docs:

http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing

In your return, item [0, :] is c[0, :, 0] and item[1, :]is c[1, :, 1].

If you want a return of shape (2, 200, 2) where item [i, :, j] is c[i, :,
j] you could use slicing:

 c[:2, :200, :2]

or something more elaborate like:

c[np.arange(2)[:, None, None], np.arange(200)[:, None], np.arange(2)]

Jaime


>
> Is this bug fixed with higher versions of numpy?
> I do not check, since mine is from EPD and is compiled with MKL (and I
> can consider recompiling myself only under strong circumstances)
>
> Ivan
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130330/8cd0dd2a/attachment.html 


More information about the NumPy-Discussion mailing list