How to sum numpy array elements in Python

2 Answers

0 votes
import numpy as np
 
arr = np.array([[1, 2], [3, 4]], dtype = np.int64)  

sum = np.sum(arr)

print(sum)


'''
run:

10

'''

 



answered Jan 23, 2019 by avibootz
0 votes
import numpy as np
 
arr = np.array([1, 2, 3], dtype = np.int64)  

sum = np.sum(arr)

print(sum)


'''
run:

6

'''

 



answered Jan 23, 2019 by avibootz
...