I am trying to convert the following Matlab code to Python:
n = 10 ;
T = cell(1, n) ;
for k = 1 : n
T{1,k} = 20*k + rand(10) ;
end
It stored all the matrices generated from the for loop. How can I write a similar code in Python?
I am trying to convert the following Matlab code to Python:
n = 10 ;
T = cell(1, n) ;
for k = 1 : n
T{1,k} = 20*k + rand(10) ;
end
It stored all the matrices generated from the for loop. How can I write a similar code in Python?
You can use a normal list:
import numpy as np
n = 10
t = []
for k in range(n):
t.append(20 * (k+1) + np.random.rand(n,n))
print(t)
python and numpy. Might be what OP is looking for.T1=T{1,1} to see the 1st Matrix and T2=T{1,2} and so on. How can I do that in python? Thank you again.t1=t[1] to see the first array, t2=t[2] to see the second array and so on.t[0] and not t[1]. If you want to have them all in one array you can use tall =np.ravel(t).reshape(10,-1)