+ 2
How to build a matrix in python?
Declare a (n x n) matrix.
4 Antworten
+ 8
You can use the numpy module for that. It supports a matrix class.
import numpy as np
mx = np.matrix([[1,3],[8,7]])
print(mx)
>>>
[[1 3]
[8 7]]
+ 5
def a(n,m):
matrix = [[i for i in range(n)] for j in range(m)]
return matrix
+ 3
All matrices (I believe) can be implemented using 2D arrays so yeah, you can try that
0
@Kuba Siekierzynski
I need to declare a square matrix of order n and accept values in run time.