[Numpy-discussion] indexed assignment testcases
Sebastian Berg
sebastian at sipsolutions.net
Sun Jul 6 15:58:36 EDT 2014
On So, 2014-07-06 at 15:32 -0400, Benjamin Root 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
>
The shapes match using broadcasting. Values shape of (1,) can be
broadcast to indexing result shape of (0,).
>
> 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)
>
Gives a (maybe not good) deprecation warning in master. But those are
typically invisible...
>
> a[mask_in] = np.array([2.0]) # This works and repeats 2.0 twice. I
> thought this wasn't supposed to happen anymore?
>
Again, broadcasting of values onto out shape.
- Sebastian
>
> Ben Root
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140706/f8235e03/attachment.sig>
More information about the NumPy-Discussion
mailing list