[Numpy-discussion] question about subtraction and shape
tsyu80 at gmail.com
Thu Sep 1 17:44:49 EDT 2011
On Thu, Sep 1, 2011 at 5:33 PM, Jonas Wallin <jonas.wallin81 at gmail.com>wrote:
> I implemented the following line of code:
> Gami[~index0].shape ----> (100,)
> sigma.shape ----> (1,1)
> Gami[~index0] = Gam[~index0] - sigma**2
> I get the error message:
> *** ValueError: array is not broadcastable to correct shape
> *temp* = Gam[~index0] - sigma**2
> *temp*.shape --> (1,100)
> Which seems strange to me is there any reason why *temp* gets this shape ?
Numpy changes the shape of the output array based on certain broadcasting
rules (See http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html).
Broadcasting is really useful when you need it, but it can be confusing when
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion