Hi,
Is there a way for me to keep adding the next row of a 2d array to a
file via load? (matlab's save had a very useful -append option).
I managed to get 2d laod/save working, e.g.
import numpy as N
import pylab as P
import bthom.utils as U
# a numpy 2d array
a = N.arange(12,dtype=N.float).reshape((3,4))
a[0][0] = N.pi
# checking out the matploblib save/load stuff
P.save("data.csv", a, fmt="%.4f", delimiter=";")
aa = P.load("data.csv", delimiter= ";")
x,y,z,w = P.load("data.csv", delimiter=";", unpack=True)
The above took me longer than it perhaps should have b/c of advice
I'd gotten elsewhere recommending trying to keep numpy and pylab
separate when possible (to take advantage of all of numpy's features;
it seems numpy doesn't even have the all-to-handy load/save
functionality).
When I try similar tricks to write one row at a time, I'm hosed in
that the shape is gone:
# checking out a way to keep appending
fname = "data1.csv"
U.clobber_file(fname) #this thing just ensures 0 bytes in file
f = open(fname,"a")
nrows,ncols = a.shape
for i in range(nrows) :
P.save(f, a[i,:], fmt="%d", delimiter=";")
f.close()
aaa = P.load("data1.csv", delimiter= ";")
in particular:
% cat data1.csv
3
1
2
4
<snip>
11
Thanks in advance,
--b
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users