Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,862 questions

51,784 answers

573 users

How to find the sum of rows and columns of a given matrix using numpy in Python

1 Answer

0 votes
import numpy as np

matrix = np.matrix([[1, 2, 3], [4, 4, 6]])
print(matrix)

sum_of_rows = np.sum(matrix, axis = 1)
print("Sum of rows =\n", sum_of_rows)

sum_of_cols = np.sum(matrix, axis = 0)
print("Sum of columns =", sum_of_cols)



'''
run:

[[1 2 3]
 [4 4 6]]
Sum of rows =
 [[ 6]
 [14]]
Sum of columns = [[5 6 9]]

'''

 



answered Jun 24, 2023 by avibootz

Related questions

1 answer 113 views
1 answer 156 views
1 answer 222 views
222 views asked Jan 25, 2019 by avibootz
1 answer 118 views
1 answer 137 views
...