# How to find the sum of each row and column of a matrix in python language

How to find the sum of each row and column of a matrix in __python language__. There are you will learn how to find the sum of each row & column of a matrix.

Take an example to find out this solution through a __python program__:

```
# How to find the sum of each row and column
# of a matrix in python language
print ("-----Enter the number of rows & columns of the matrix-----")
# These are the matrix's dimension
x = int (input ())
y = int (input ())
a, sum = [], 0
print ("\n-----Enter the co-efficients of the matrix-----")
for i in range (x):
a.append([])
for j in range (y):
a[i].append(int (input ()))
print (end="\n")
# This statement will compute the
# sum of the matrix's rows elements
for i in range (x):
for j in range (y):
sum = sum + a[i][j]
print ("The Sum of the ", i, " position row is = ", sum)
sum = 0
print (end="\n")
sum = 0
# This statement will compute the
# sum of the matrix's columns elements
for j in range (y):
for i in range (x):
sum = sum + a[i][j]
print ("The Sum of the ", j, " position column is = ", sum)
sum = 0
```

**Output:**

`-----Enter the number of rows & columns of the matrix-----`

4

3

`-----Enter the co-efficients of the matrix-----`

12

23

12

`34`

12

43

`34`

53

12

`56`

34

23

`The Sum of the 0 position row is = 47`

The Sum of the 1 position row is = 89

The Sum of the 2 position row is = 99

The Sum of the 3 position row is = 113

`The Sum of the 0 position column is = 136`

The Sum of the 1 position column is = 122

The Sum of the 2 position column is = 90

## Tags:

# write a program to find the sum of all elements in a matrix in python

# write a python program to calculate the sum of all even elements of a matrix

# write a program to find the sum of matrix elements in python using functions