You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: Incorrect shape of broadcast result with the exponentiation operator **. #4145
I haven't explored the full range of inputs that produce the error, but when x has shape (n,) and y has shape (1,1), the result of x ** y does not have the correct (broadcast) shape. It should be (1, n), but in all the numpy versions I've tried (1.6.1, 1.7.1, 1.8.0, and 1.9.0.dev-e7fe68a), the result has shape (n,).
Also, in numpy 1.8.0 and 1.9.0.dev-e7fe68a, the operation generates an unexpected DeprecationWarning.
The following shows an example. Python was run with the command python -W always.
>>> np.__version__
'1.8.0'
>>> x
array([1, 2])
>>> y = np.array([[2]])
>>> x ** y # This should not generate a warning. Result should be `array([[1, 4]])`
__main__:1: DeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
array([1, 4])
>>> x + y # No warning, correct shape.
array([[3, 4]])
>>> y = np.array([[2], [3]])
>>> x ** y # No warning, correct shape.
array([[1, 4],
[1, 8]])
Are we going to fix this for numpy 1.8.x? Otherwise, just finishing up that deprecation will fix the issue. It is a rather corner case deprecation warning, so it may be possible to just finish the deprecation in 1.9 already.
Well, if you set warnings.filterwarnings('error') to raise the deprecation warning, you get the correct result, because trying to interpret the second array as an integer fails. That said, trying to interpret it as an integer when it already is an array does not make sense, so the __pow__ code should be fixed.
Why does pow have a special case for integers anyway? We don't switch
to matrix exponentiation or anything like that, right?
On 26 Dec 2013 13:05, "seberg" [email protected] wrote:
Well, if you set warnings.filterwarnings('error') to raise the
deprecation warning, you get the correct result, because trying to
interpret the second array as an integer fails. That said, trying to
interpret it as an integer when it already is an array does not make sense,
so the pow code should be fixed.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/4145#issuecomment-31235793
.
Activity
seberg commentedon Dec 26, 2013
Are we going to fix this for numpy 1.8.x? Otherwise, just finishing up that deprecation will fix the issue. It is a rather corner case deprecation warning, so it may be possible to just finish the deprecation in 1.9 already.
WarrenWeckesser commentedon Dec 26, 2013
What do you mean by "just finishing up that deprecation will fix the issue"?
seberg commentedon Dec 26, 2013
Well, if you set
warnings.filterwarnings('error')to raise the deprecation warning, you get the correct result, because trying to interpret the second array as an integer fails. That said, trying to interpret it as an integer when it already is an array does not make sense, so the__pow__code should be fixed.njsmith commentedon Dec 26, 2013
Why does pow have a special case for integers anyway? We don't switch
to matrix exponentiation or anything like that, right?
On 26 Dec 2013 13:05, "seberg" [email protected] wrote:
seberg commentedon Dec 26, 2013
Ah, will open a PR with a fix... Apparently because we optimize (x ** 2) and some other operations like that.
BUG: Only convert 0d arrays to scalars in power