[Numpy-discussion] Strange behavior with boolean slices...
Cera, Tim
tim at cerazone.net
Sun Aug 25 21:06:35 EDT 2013
Pardon the noise. The behavior is described right there in the
documentation of broadcast_arrays.
Kindest regards,
Tim
On Sun, Aug 25, 2013 at 8:53 PM, Cera, Tim <tim at cerazone.net> wrote:
> Figured it out. I created 'day' as a broadcast array. Does this
> catch other people? Basically changing day[0] would change the entire
> 'day' array. I guess all other elements of the day array are views of
> day[0]. Made a copy and everything works as expected.
>
> Kindest regards,
> Tim
>
> On Sun, Aug 25, 2013 at 8:44 PM, Eric Firing <efiring at hawaii.edu> wrote:
>> On 2013/08/25 2:30 PM, Cera, Tim wrote:
>>> I have done this before, but am now really confused.
>>>
>>> Created an array 'day' specifying the 'f' type
>>>
>>> In [29]: day
>>> Out[29]: array([ 5., 5.], dtype=float32)
>>>
>>> # Have a mask...
>>> In [30]: mask
>>> Out[30]: array([ True, False], dtype=bool)
>>>
>>> # So far, so good...
>>> In [31]: day[mask]
>>> Out[31]: array([ 5.], dtype=float32)
>>>
>>> In [32]: day[mask] = 10
>>>
>>> # What?
>>> In [33]: day
>>> Out[33]: array([ 10., 10.], dtype=float32)
>>
>> I'm not getting that with 1.7.0:
>> In [2]: np.__version__
>> Out[2]: '1.7.0'
>>
>> In [3]: mask = np.array([True, False], dtype=bool)
>>
>> In [4]: day = np.array([5, 5], dtype=np.float32)
>>
>> In [5]: day
>> Out[5]: array([ 5., 5.], dtype=float32)
>>
>> In [6]: mask
>> Out[6]: array([ True, False], dtype=bool)
>>
>> In [7]: day[mask]
>> Out[7]: array([ 5.], dtype=float32)
>>
>> In [8]: day[mask] = 10
>>
>> In [9]: day
>> Out[9]: array([ 10., 5.], dtype=float32)
>>
>> Eric
>>
>>
>>>
>>>
>>> So I created an integer array 'a'
>>>
>>> In [38]: a
>>> Out[38]: array([11, 1])
>>>
>>> In [39]: a[mask]
>>> Out[39]: array([11])
>>>
>>> In [40]: a[mask] = 12
>>>
>>> # This is what I expect.
>>> In [41]: a
>>> Out[41]: array([12, 1])
>>>
>>> Am I missing something? Is this supposed to happen?
>>>
>>> Version 1.7.1.
>>>
>>> Kindest regards,
>>> Tim
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>
>> _______________________________________________
>> 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