
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.
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

On Sat, Mar 30, 2013 at 11:01 AM, Ivan Oseledets ivan.oseledets@gmail.comwrote:
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-inde...
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
participants (2)
-
Ivan Oseledets
-
Jaime Fernández del Río