How to add a new row to an empty numpy array
Using standard Python arrays, I can do the following:
arr = []
arr.append([1,2,3])
arr.append([4,5,6])
# arr is now [[1,2,3],[4,5,6]]
However, I cannot do the same thing in numpy. For example:
arr = np.array([])
arr = np.append(arr, np.array([1,2,3]))
arr = np.append(arr, np.array([4,5,6]))
# arr is now [1,2,3,4,5,6]
I also looked into vstack
, but when I use vstack
on an empty array, I get:
ValueError: all the input array dimensions except for the concatenation axis must match exactly
So how do I do append a new row to an empty array in numpy?