[Numpy-discussion] Strange behavior with boolean slices...
Eric Firing
efiring at hawaii.edu
Sun Aug 25 20:44:30 EDT 2013
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
>
More information about the NumPy-Discussion
mailing list