forked from sakshamchecker/Hacktoberfest-21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpyMatrices.py
40 lines (32 loc) · 925 Bytes
/
numpyMatrices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
import random
from numpy.random.mtrand import rand
# Array Initialization
row = int(input("Enter no. of rows: "))
col = int(input("Enter no. of columns: "))
array1 = np.zeros((row,col))
array2 = np.zeros((row,col))
# Fill arrays with random values
for i in range(row):
for j in range(col):
array1[i][j] = random.randint(1,100)
array2[i][j] = random.randint(1,100)
print("\nMatrix 1:")
print(array1)
print("\nMatrix 2:")
print(array2)
# Sum of Matrices
result_arr = np.zeros((row,col))
for i in range(row):
for j in range(col):
result_arr[i][j] = array1[i][j] + array2[i][j]
print("\nSum of both matrices: ")
print(result_arr)
# Transpose of resultant matrix
transpose_arr = np.zeros((col,row))
for i in range(col):
for j in range(row):
transpose_arr[i][j]=result_arr[j][i]
print("\nTranspose of the resultant matrix: ")
print(transpose_arr)
print("\n")