[Numpy-discussion] Broadcasting rules (Ticket 76).

Zachary Pincus zpincus at stanford.edu
Mon Apr 24 10:57:04 EDT 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 [1]: import numpy
In [2]: numpy.__version__
'0.9.7.2335'
In [3]: a = numpy.ones([50, 100])
In [4]: means = a.mean(axis = 1)
In [5]: print a.shape, means.shape
(50, 100) (50,)
In [5]: a / means
ValueError: index objects are not broadcastable to a single shape
In [6]: (a.transpose() / means).transpose()
#this works

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.

Zach




More information about the NumPy-Discussion mailing list