[Numpy-discussion] 'append' array method request.

Robert Hetland hetland at tamu.edu
Fri Apr 21 15:02:12 CDT 2006

I find myself writing things like

x = []; y = []; t = []
for line in open(filename).readlines():
     xstr, ystr, tstr = line.split()
     t.append(dateutil.parser.parse(tstr))  # or something similar
x = asarray(x)
y = asarray(y)
t = asarray(t)

I think it would be nice to be able to create empty arrays, and  
append the values onto the end as I loop through the file without  
creating the intermediate list.  Is this reasonable?  Is there a way  
to do this with existing methods or functions that I am missing?  Is  
there a better way altogether?


Rob Hetland, Assistant Professor
Dept of Oceanography, Texas A&M University
p: 979-458-0096, f: 979-845-6331
e: hetland at tamu.edu, w: http://pong.tamu.edu

More information about the Numpy-discussion mailing list