0

I have a list of numpy arrays. My list contains 5000 numpy arrays and each one has the size (1x1000). I want to construct a numpy array of size 5000x1000. I am trying to do something like:

db_array = np.asarray(db_list) # my db_list has 5000 samples of 1x1000 size

The result was a matrix of size (5000, 1, 1000). How can I construct a matrix with size (5000, 1000)?

4
  • You can use .reshape(5000,1000) Commented Mar 21, 2018 at 10:30
  • Just reshape the array Commented Mar 21, 2018 at 10:30
  • I tried reshape and the reuslt was the same. db_array = db_array.reshape(5000, 1000). I got (5000, 1, 1000) when I tried db_array.shape Commented Mar 21, 2018 at 10:34
  • vstack is another option. Commented Mar 21, 2018 at 10:41

2 Answers 2

2

An MCVE would help here, but if I understand correctly, just use the numpy.array constructor.

>>> import numpy as np
>>> arraylist = [np.array([1,2,3]), np.array([1,2,3])]
>>> arraylist
[array([1, 2, 3]), array([1, 2, 3])]
>>> np.array(arraylist)
array([[1, 2, 3],
       [1, 2, 3]])
Sign up to request clarification or add additional context in comments.

2 Comments

As a matter of fact in order to work I convert the list using the the np.array() but then i needed also to reshape. With np.asarray() it did not work.
@konstantin then your list does have a different format than the one in my demo which you did not tell us about.
2

So, just initialize the list as a simple numpy array

import numpy as np

list = [np.array([1,2,3]), np.array([1,2,3])]
new_array = np.array(list)
print (new_array)
print (new_array.shape)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.