Summing elements of numpy array in Python

deepesh

I have an numpy array

>>> clf_prob.dtype()

array([[ 0.05811791,  0.06526527,  0.06024136, ...,  0.06972481],
       [ 0.06093686,  0.06357167,  0.06462331, ...,  0.06999094],
       [ 0.08188396,  0.08504034,  0.0820972 , ...,  0.08487802],
       [ 0.05197106,  0.0786195 ,  0.15669477, ...,  0.0893244]])

I'm trying to add elements of these arrays such that my output would be:

[[0.05811791 + 0.06526527 + 0.06024136 +...+ 0.06972481],
[0.06093686 + 0.06357167 + 0.06462331 +...+0.06999094],
[0.08188396 + 0.08504034 + 0.0820972 + ...+  0.08487802],
[0.05197106 + 0.0786195  + 0.15669477+ ...+ 0.0893244]]

I tried doing

sum(map(sum, clf_prob))

This doesn't gives me desired output. Any suggestion?

Mathias711

You can do

clf_prob.sum(axis=1)

This will take the sum over a certain axis, in this case rows.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Summing up non-zero elements in numpy array

From Java

Shift elements in a numpy array

From Dev

Vary the elements in a numpy array

From Dev

Aggregate Numpy Array By Summing

From Dev

Multiplying each element of a numpy array and summing it up

From Dev

Manipulating array elements in NumPy

From Dev

Summing and removing repeated elements of Numpy Arrays

From Dev

Python: Optimize deletion of elements not aligned in a numpy array

From Dev

Python/Numpy - calculate sum of equal array elements

From Dev

Python: How to index the elements of a numpy array?

From Dev

Summing elements of string in Python

From Dev

Summing elements of array

From Dev

Order of elements in a numpy array

From Dev

Increment elements of a subset of elements in a 3d numpy array python

From Dev

Merging numpy array elements using join() in python

From Dev

Summing data from array based on other array in Numpy

From Dev

Summing elements in a sliding window - NumPy

From Dev

Padding elements of a numpy array

From Dev

In Python/NumPy, how to pad an array by replicating the elements?

From Dev

Multiplying each element of a numpy array and summing it up

From Dev

Python: Optimize deletion of elements not aligned in a numpy array

From Dev

Summing elements on an array of d3 objects

From Dev

Summing positive and negative elements from two NumPy arrays

From Dev

Python: How to index the elements of a numpy array?

From Dev

Summing elements in a sliding window - NumPy

From Dev

Summing array entries along a particular line, python

From Dev

Summing grouped items in a numpy array without looping

From Dev

Summing elements of the array - MIPS

From Dev

Summing up elements in array using managedCuda

Related Related

HotTag

Archive