In: Computer Science
Using Python :
Create a 4×5 4 × 5 array ? X with random value. Print out ? X , as well as the largest value of each column.
Please find the answer below, Have mentioned all the details in the comments.
matrix.py:
import random as r
#row count
m = 4
#column count
n = 5
#matrix
X = []
#loops to generate the matrix with random values
for i in range(m):
row = []
for j in range(n):
# you need to increment through dataList here, like this:
row.append(r.random())
X.append(row)
#print matrix
print(X)
#to print max from each column
for j in range(n):
max_col = -1;
for i in range(m):
if(X[i][j] > max_col):
max_col = X[i][j]
print("Max in coloumn ", j , " is: ",max_col)
Output:
Please find the picture of the code snippet for your reference of the code indentaion: