[Numpy-discussion] indexed assignment testcases

Nathaniel Smith njs at pobox.com
Sun Jul 6 17:48:13 EDT 2014


On Sun, Jul 6, 2014 at 9:14 PM, Benjamin Root <ben.root at ou.edu> wrote:
> as for the broadcasting issue, I can see it for the second case, but the
> first case still doesn't sit right with me. My understanding of broadcasting
> is to effectively *expand* an array to match the shape of another array (or
> some target shape). In this case, the array is being effectively
> *contracted* in shape. That makes zero sense to me.

That's how it's always worked though, in all cases of broadcasting;
nothing special about indexing:

In [8]: a = np.zeros((3, 0))

In [9]: a + 1
Out[9]: array([], shape=(3, 0), dtype=float64)

In [10]: a + [[1], [2], [3]]
Out[10]: array([], shape=(3, 0), dtype=float64)

IME it's extremely useful in practice for avoiding special cases when
some axis has a vary size that can be zero.

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org



More information about the NumPy-Discussion mailing list