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?
If the number of elements in
lineis fixed and you just want to avoid an “ugly” solution, you can do this: