br is the name of a string list that looks like this:
['14 0.000000 -- (long term 0.000000)\n', '19 0.000000 -- (long term 0.000000)\n', '22 0.000000 -- (long term 0.000000)\n', ...
I am interested in the first two columns that I would like to convert to a numpy array. So far I have come up with the following solution:
x = N.array ([0., 0.]) for i in br: x = N.vstack ( (x, N.array (map (float, i.split ()[:2]))) )
The result is a two-dimensional array:
array([[ 0., 0.], [ 14., 0.], [ 19., 0.], [ 22., 0.], ...
However, since br quite large (~ 10 ^ 5 entries), this procedure takes some time. I was wondering if there is a way to achieve the same result, but in less time?
source share