0

I'm trying to work around the issue of building a numpy array using a generator as noted here. To get around this I define the following function:

list_of_np_arrays = []
for i in generator:
    list_of_np_arrays.append(np.array(i)) # i shape is (n:2)
# convert list to numpy array
list_of_np_arrays = np.asarray(list_of_np_arrays)

I have:

array([array([[   0,    1],
   [   1,    1],
   [   2,    1],
   [1004,    3],
   [1005,    1],
   [1006,    1]]),
   array([[  12,    1],
   [  23,    2],
   [  25,    1],
   [1665,    2],
   [1666,    1],
   [1667,    1]])], dtype=object)

I want:

array([
   [   0,    1],
   [   1,    1],
   [   2,    1],
   [1004,    3],
   [1005,    1],
   [1006,    1],
   [  12,    1],
   [  23,    2],
   [  25,    1],
   [1665,    2],
   [1666,    1],
   [1667,    1]], dtype=object)

Is there a best practice for handling this situation?

2
  • 2
    np.concatenate(a) or np.vstack(a)? Commented Dec 1, 2016 at 21:34
  • i thought it would be something very simple...vstack worked perfectly. thank you @Divakar Commented Dec 1, 2016 at 21:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.