Professional Documents
Culture Documents
8: Computing With Numpy: in The Documentation
8: Computing With Numpy: in The Documentation
8: Computing With Numpy: in The Documentation
sum() -- computes the sum of all the elements in a vector, or the sum
along a dimension in a matrix.
The code above would add together all of the elements in vector, and result
in 50.
matrix = numpy.array([
[5, 10, 15],
[20, 25, 30],
[35, 40, 45]
])
matrix.sum(axis=1)
The code above would compute the sum for each row, resulting in [30, 75,
120].