Reputation: 519
I have tried to add numpy arrays (multiple of numpy_array
) in a for loop to a list where each numpy array might have varies shapes like (but let us say each has (10, 64)). So each array has 64 columns and might have as many rows as possible. What I did was the following:
l_arr = numpy_array[indices, :]
list_arr.append(l_arr.tolist())
Then,
numpy_from_list= np.array(list_arr)
But this seems to add extra dimension. For example If I added 3 numpy arrays each of size (10, 64) to a list and then convert a list to a numpy. I would get (3, 10, 64)
, but instead I want (30, 64)
.
for i in range(3):
l_arr = numpy_array[indices, :]
list_arr.append(l_arr.tolist())
numpy_from_list= np.array(list_arr)
Can you please help me with that?
Upvotes: 0
Views: 82
Reputation: 1835
Here you go:
arrays = [np.random.randint(0,10,(10, 64)) for i in range(3)]
res = np.vstack(arrays)
Upvotes: 1