Tuesday, April 14, 2009

Sums in NumPy

Class,

It was just pointed out to me that there is a difference between sum and np.sum. Consider the following,
>>> a = np.array([[0,2,3], [5,2,3]], float)
>>> sum(a)
array([ 5., 4., 6.])
>>> np.sum(a)
15.0
The sum function will only sum an array along the smallest axis, while the np.sum function sums the entire array. For your dot products, you want to use the np.sum function instead of just sum.

MSS

No comments: