[Numpy-discussion] ndarray.T2 for 2D transpose

Nathaniel Smith njs at pobox.com
Thu Apr 7 16:37:56 EDT 2016


On Thu, Apr 7, 2016 at 10:00 AM, Ian Henriksen
<insertinterestingnamehere at gmail.com> wrote:
>
> Here's another example that I've seen catch people now and again.
>
> A = np.random.rand(100, 100)
> b =  np.random.rand(10)
> A * b.T
>
> In this case the user pretty clearly meant to be broadcasting along the rows
> of A
> rather than along the columns, but the code fails silently. When an issue
> like this
> gets mixed into a larger series of broadcasting operations, the error
> becomes
> difficult to find.

I feel like this is an argument for named axes, and broadcasting rules
that respect those names, as in xarray? There's been some speculative
discussion about adding something along these lines to numpy, though
nothing that's even reached the half-baked stage.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org



More information about the NumPy-Discussion mailing list