I read linewise data from a file and I want to store them in an array.
EDIT: The data cannot be read with loadtxt().
So I do it like this:
data = array([])
for frame in frames:
# ....
# get some lines and make some calculations e.g. final result is
# line = array([1, 2, 3, 4])
# ....
if data.size == 0:
data = line
else:
data = vstack( (data, line) )
This works fine, but the if-clausel make the solution just look ugly. I wonder if there is a possibility to get ride of it.
Any ideas?
data = vstack((data, line)) if data else line?np.concatenate(or its specialized derivatives) for speed reasons.vstackproblem itself, the solution is to usedata = np.empty((0,4)), but using a temporary list is probably better (or best you already know the arrays size and just fill it)