[Numpy-discussion] Bug? numpy.matrix.sum()
Alan G Isaac
aisaac at american.edu
Fri Jan 20 07:03:03 CST 2006
On Fri, 20 Jan 2006, Norbert Nemec apparently wrote:
> In [1]: import numpy
> In [2]: numpy.__version__
> Out[2]: '0.9.2'
> In [3]: a = numpy.matrix(numpy.eye(2))
> In [4]: a.sum()
> Out[4]: matrix([[1, 0, 0, 1]])
> In [5]: a.A.sum()
> Out[5]: 2
> In [6]: sum(a)
> Out[6]: matrix([[1, 1]])
> In [7]: sum(a.A)
> Out[7]: array([1, 1])
Only [4] looks wrong.
However it works "right" if you provide a numerical axis
argument. (I put "right" in quotes because it is not clear
to me that a row vector is expected as the result when
summing columns.) The default is axis=None, which is not
working as expected for matrices.
Cheers,
Alan Isaac
More information about the Numpy-discussion
mailing list