[Numpy-discussion] 'append' array method request.
Charles R Harris
charlesr.harris at gmail.com
Fri Apr 21 18:50:02 EDT 2006
Hi,
On 4/21/06, Robert Hetland <hetland at tamu.edu> wrote:
>
>
> I find myself writing things like
>
> x = []; y = []; t = []
> for line in open(filename).readlines():
> xstr, ystr, tstr = line.split()
> x.append(float(xstr))
> y.append(float(ystr)_
> t.append(dateutil.parser.parse(tstr)) # or something similar
> x = asarray(x)
> y = asarray(y)
> t = asarray(t)
I think you can read the ascii file directly into an array with numeric
conversions (fromfile) then just reshape it to have x,y,z columns. For
example:
$[charris at E011704 ~]$ cat input.txt
1 2 3
4 5 6
7 8 9
Then after importing numpy into ipython:
In [6]:fromfile('input.txt',sep=' ').reshape(-1,3)
Out[6]:
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060421/34c2ff88/attachment-0001.html>
More information about the NumPy-Discussion
mailing list