How to write this in cycle, please?
k1 = np.empty(np.shape(u))
k2 = np.empty(np.shape(u))
k3 = np.empty(np.shape(u))
k4 = np.empty(np.shape(u))
I tried:
k = [k1, k2, k3, k4]
for i in k:
i = np.empty(np.shape(u))
k.append(i)
How to write this in cycle, please?
k1 = np.empty(np.shape(u))
k2 = np.empty(np.shape(u))
k3 = np.empty(np.shape(u))
k4 = np.empty(np.shape(u))
I tried:
k = [k1, k2, k3, k4]
for i in k:
i = np.empty(np.shape(u))
k.append(i)
You can simply use list comprehension to create an arbitrary number of empty numpy arrays
num = 10
result = [np.empty(np.shape(u)) for _ in range(num)]
It is not a good practice to do this, so I would recommend using lists or dictionaries but here's the code to achieve what you asked for-
for x in range(0, n): #Replace n with the value you need
globals()['k%s' % x] = np.empty(np.shape(u))
and then for example:
print(k1)
But again this is a bad practice, use dictionaries instead