[Numpy-discussion] is it a bug?

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Mar 11 22:58:50 EDT 2009


On Wed, Mar 11, 2009 at 9:51 PM, Jonathan Taylor
<jonathan.taylor at utoronto.ca> wrote:
> You lost me on
>> x = np.arange(30)
>> x.shape = (2,3,5)
>
> For me I get:
> In [2]: x = np.arange(30)
>
> In [3]: x.shape
> Out[3]: (30,)
>
> which is what I would expect.   Perhaps I missed something?
>
> Jon.
> - Show quoted text -
> On Wed, Mar 11, 2009 at 8:55 PM, shuwj5460 at 163.com <shuwj5460 at 163.com> wrote:
>> Hi,
>>
>> import numpy as np
>> x = np.arange(30)
>> x.shape = (2,3,5)
>>
>> idx = np.array([0,1])
>> e = x[0,idx,:]
>> print e.shape
>> #----> return (2,5). ok.
>>
>> 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.
>>
>>
>> Regards
>>
>> David

same problem with reshape instead of assigning to shape:

>>> x = np.arange(30).reshape(2,3,5)
>>> idx = np.array([0,1]); e = x[0,:,idx]; e.shape
(2, 3)
>>> idx = np.array([0,1]); e = x[0,:,:2]; e.shape
(3, 2)
>>> e = x3[0,:,[0,1]];e.shape
(2, 3)
>>> e = x3[0,np.arange(3)[:,np.newaxis],[0,1]]; e.shape
(3, 2)
>>> e = x3[0,0:3,[0,1]];e.shape
(2, 3)

I was trying to figure out what the broadcasting rules are doing, but
the combination of slice : and an index looks weird, and I'm using
this pattern all the time.

Josef



More information about the NumPy-Discussion mailing list