I need to stack numpy array vertically, which are a return value from function_returns_some_np_array
. The function always returns an array of the same shape. In this case is length is 10. If I do not check if X is not empty, I get the following error.
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 10
The code including check:
X = np.empty(0)
if X.size == 0:
X = function_returns_some_np_array(data)
else:
X = np.vstack((X, function_returns_some_np_array(data)))
Is it always necessary to check whether the array is not empty or is there a one line solution to handle this? Something build-in would be great. So to sum up the question. Is there maybe a shorter solution to this operation?
Thanks