[SciPy-User] Numpy array slicing

Eirik Gjerløw eirik.gjerlow@astro.uio...
Thu Feb 9 11:19:52 CST 2012


Hey,

I asked this at numpy-discussion as well, and it seems the issue is that 
I am mixing advanced indexing and basic slicing, and the way numpy 
handles this:

http://mail.scipy.org/pipermail/numpy-discussion/2012-February/060232.html

Anyway, there should be enough information to reproduce the problem. a 
can be any numpy array with the given shape, so

a = np.zeros((3, 4, 12288, 2))
mask = np.zeros((3, 12288), dtype='bool')
mask[:] = True
mask[0, [3, 7, 9, 15, 20]] = False

for instance.

Thanks for replying!

Eirik

On 09. feb. 2012 18:13, Oleksandr Huziy wrote:
> Hi, what will happen if you do:
>
> a[[0] + [slice(None)] + [[mask[0]]] + [slice(None)]].shape
>
> please, give the code to generate the mask and the array, so we could
> test our hypotheses.
> thanks
>
> --
> Oleksandr Huziy
>
> 2012/2/9 Eirik Gjerløw<eirik.gjerlow@astro.uio.no>:
>> Hello, 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
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list