numpy.sum() returns 0-dimensional array, rather than a scalar
Issue #57
resolved
The numpy function sum()
returns a 0-dimensional numpy array instead of a scalar. This results in breakage when interacting with objects and methods that expect a scalar type. I encountered this problem when using numpy with sympy:
import numpy as np
from sympy import symbols
x = symbols('x')
# Works
foo = np.array([1, 2, 3, 4]).sum() * x
print(foo.subs({x: 20}))
# Does not work
bar = np.sum([1, 2, 3, 4]) * x
print(bar.subs({x: 20}))
This script prints 200
twice when run in CPython (or when run in pypy using upstream numpy with cpyext), but only prints 200
once and fails with the following error message using Pypy numpy:
Traceback (most recent call last):
File "pypy_test.py", line 14, in <module>
print(bar.subs({x: 20}))
AttributeError: 'numpy.ndarray' object has no attribute 'subs'
Comments (2)
-
-
- changed status to resolved
fixed, the issue was in _numpypy from pypy
- Log in to comment
should be fixed in pypy d86329133431, try a subsequent nightly (after the commit) http://buildbot.pypy.org/nightly/trunk/