[Numpy-discussion] indexed assignment testcases
Charles R Harris
charlesr.harris at gmail.com
Sun Jul 6 15:59:00 EDT 2014
On Sun, Jul 6, 2014 at 1:32 PM, Benjamin Root <ben.root at ou.edu> wrote:
> While trying to wrap my head around the issues with matplotlib's tri
> module and the new numpy indexing, I have made some test cases where I
> wonder if warnings should be issued.
>
> import numpy as np
> a = np.ones((10,))
> all_false = np.zeros((10,), dtype=bool)
> a[all_false] = np.array([2.0]) # the shapes don't match here
>
It broadcasts because the leading dimension is 1.
>
> mask_in = np.array([False]*8 + [True, True])
> a[mask_in] = np.array([]) # raises ValueError as expected
> a[mask_in] = np.array([[]]) # no exception because it is 2-D, for some
> reason (on master, but not release-0.9b1)
>
Now falls back to old behavior and raises a DeprecationWarning. You don't
see that by default.
>
> a[mask_in] = np.array([2.0]) # This works and repeats 2.0 twice. I thought
> this wasn't supposed to happen anymore?
>
Broadcasting again.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140706/6d542e59/attachment.html>
More information about the NumPy-Discussion
mailing list