Home > OS >  Storing Multiple Matrices from a For Loop in Python
Storing Multiple Matrices from a For Loop in Python

Time:09-26

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?

CodePudding user response:

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)
  • Related