In my codes, I created a list with n np.arrays with various length.
Sample of how to create the list:
MyArr = [None] * n
for l in range(n):
MyArr[l] = np.array([1, 2, 3]) # Example 1
# MyArr[l] = np.array([-1, -10]) # Example 2
What I eventually want to do is make MyArr an 1D numeric array, like the following:
MyArr = [np.array([1, 2, 3]), np.array([1, 2]), np.array([10]), np.array([-1, -2, -3])]
Into:
np.array([1, 2, 3, 1, 2, 10, -1, -2, -3])
Because n is pretty large, I think using a for loop is not a good idea. What do you guys think?
numpy.flattenwill do the trick.flattenis a method, so you can apply it onMyArrbut on nd-array. So its not whats needed in this case.