[Numpy-discussion] A bug in numpy.random.shuffle?

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Sep 5 23:16:04 EDT 2013


On Thu, Sep 5, 2013 at 9:33 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
>
>
> On Thu, Sep 5, 2013 at 3:40 PM, <josef.pktd at gmail.com> wrote:
>>
>> >> >
>> >> > In [4]: x[0], x[1] = x[1], x[0]
>>
>> Is this ever predictable?
>> sounds to me like the inplace question a few days ago
>> result depends on the underlying iterator
>>
>> >>> a = np.arange(5*3).reshape((5,3), order='F')
>> >>> a
>> array([[ 0,  5, 10],
>>        [ 1,  6, 11],
>>        [ 2,  7, 12],
>>        [ 3,  8, 13],
>>        [ 4,  9, 14]])
>> >>> b = a[::-1]
>> >>> b
>> array([[ 4,  9, 14],
>>        [ 3,  8, 13],
>>        [ 2,  7, 12],
>>        [ 1,  6, 11],
>>        [ 0,  5, 10]])
>> >>> b[0], b[1] = b[1], b[0]
>> >>> b
>> array([[ 3,  8, 13],
>>        [ 3,  8, 13],
>>        [ 2,  7, 12],
>>        [ 1,  6, 11],
>>        [ 0,  5, 10]])
>> >>> a
>> array([[ 0,  5, 10],
>>        [ 1,  6, 11],
>>        [ 2,  7, 12],
>>        [ 3,  8, 13],
>>        [ 3,  8, 13]])
>>
>> The example works as "expected" if a is 1d
>
>
> The rows are views, so that is expected. What is unexpected is that the
> void/string scalars are also views.

I don't see it with string, only with structured dtypes IIUC

>>> b = np.arange(5).astype('S2')
>>> b
array(['0', '1', '2', '3', '4'],
      dtype='|S2')
>>> b[1], b[0] = b[0], b[1]
>>> b
array(['1', '0', '2', '3', '4'],
      dtype='|S2')
>>> b[0], b[1] = b[1], b[0]
>>> b
array(['0', '1', '2', '3', '4'],
      dtype='|S2')
>>> type(b[0])
<type 'numpy.string_'>
>>> np.__version__
'1.5.1'


>
> Chuck
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list