[Numpy-discussion] Broadcasting rules (Ticket 76).
zpincus at stanford.edu
Mon Apr 24 10:57:04 CDT 2006
> It would be very difficult to change the other broadcasting
> behavior which was inherited from Numeric, however. The only
> possibility I see is adding new useful functionality where Numeric
> used to raise an error.
Well, there is one case that I run into all of the time where the
broadcasting rules seem a bit constraining:
In : import numpy
In : numpy.__version__
In : a = numpy.ones([50, 100])
In : means = a.mean(axis = 1)
In : print a.shape, means.shape
(50, 100) (50,)
In : a / means
ValueError: index objects are not broadcastable to a single shape
In : (a.transpose() / means).transpose()
It's obvious why this doesn't work due to the broadcasting rules, but
it also seems (to me, in this case at least) obvious what I am trying
to do. I don't think I'm suggesting that the broadcasting rules be
changed to allow matching-from-the-right in the general case, since
that seems likely to make the broadcasting rules even more difficult
to grok. But there do seem to be a lot of (....transpose
() ... ).transpose() bits in my code.
Is there anything to be done here? I presume not, but I just wanted
to mention it.
More information about the Numpy-discussion