Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8
import numpy as np matrix = np.arange(1,10).reshape(3,3)
24th Aug 2019, 4:49 AM
Thoq!
Thoq! - avatar
24th Aug 2019, 3:23 PM
Anwar Ali
Anwar Ali - avatar
+ 5
R = int(input("enter the number of rows :")) C = int(input("enter the number ofcolumns :")) matrix = [ ] print ("enter the entries row wise:") for i in range(R): a = [ ] for j in range(C): a. append(int(input())) matrix. append(a) for i in range(R): for j in range(C): print (matrix[i][j], end = " " ) print()
23rd Aug 2019, 4:17 PM
Vanaja
Vanaja - avatar
+ 4
matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] or matrix = [[j + i*3 + 1 for j in range(3)] for i in range(3)]
23rd Aug 2019, 4:49 PM
Anton Böhler
Anton Böhler - avatar
+ 2
generating a matrix n = [int(i) for i in input().split()] matrix = [n[i:i+3] for i in range(0,len(n),3)]
23rd Aug 2019, 9:37 PM
Choe
Choe - avatar
+ 2
a=0 for i in range(1,4): for j in range(1,4): a+=1 print(a,end="") print("")
25th Aug 2019, 10:31 AM
Rishikesh Kumar
Rishikesh Kumar - avatar
+ 1
If your matrix stores same type, use numpy for it. It’s efficient! On the other hand, use nest lists to create matrix. But it’s not common. Personal recommendation: numpy, pandas. These two libraries are popular and efficient compared with Python list or dict because of their structure. Good luck!
25th Aug 2019, 1:01 AM
Aaron Yang
Aaron Yang - avatar