[Numpy-discussion] is it a bug?

Stéfan van der Walt stefan@sun.ac...
Thu Mar 12 01:34:20 CDT 2009


2009/3/12 Robert Kern <robert.kern@gmail.com>:
>> idx = np.array([0,1])
>> e = x[0,:,idx]
>> print e.shape
>>
>> #-----> return (2,3). I think the right answer should be (3,2). Is
>> #       it a bug here? my numpy version is 1.2.1.
>
> It's certainly weird, but it's working as designed. Fancy indexing via
> arrays is a separate subsystem from indexing via slices. Basically,
> fancy indexing decides the outermost shape of the result (e.g. the
> leftmost items in the shape tuple). If there are any sliced axes, they
> are *appended* to the end of that shape tuple.

This was my understanding, but now I see:

In [31]: x = np.random.random([4,5,6,7])

In [32]: idx = np.array([1,2])

In [33]: x[:, idx, idx, :].shape
Out[33]: (4, 2, 7)

Cheers
Stéfan


More information about the Numpy-discussion mailing list