ascii input/output cookbook doc
For your information: I just created a small cookbook document http://scipy.org/Cookbook/InputOutput where it is explained how one can read and write Numpy arrays in human readable (ascii) format. The document describes how one can use read_array/write_array if SciPy is installed, or how one can use load/save if Matplotlib is installed. When neither of these two packages is installed, one basically has no other choice then to improvise, so I also give here a few examples how one could do this. Imho, there is something unsatisfactorily about this need to improvise. Ascii input/output of numpy arrays seems to me a very basic need. Even when one defines Numpy crudely as the N-dimensional array object, and Scipy as the science you can do with these array objects, then I would intuitively still expect that ascii input/output would belong to Numpy rather than to Scipy. There are Numpy support functions for binary format, and for pickled format, but strangely enough not really for ascii format. tofile() and fromfile() do not preserve the shape of a 2d array, and are in practice therefore hardly usable. There may be a signficant fraction of Numpy users that do not need SciPy for their work, and have only Numpy installed. My guess is that the read_array and write_array functions have already been re-invented many many times by these users. Imho, I therefore think that Numpy deserves its own read_array/write_array method. Does anyone else have this feeling, or am I the only one? :o) Joris Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
joris@ster.kuleuven.ac.be wrote:
For your information: I just created a small cookbook document http://scipy.org/Cookbook/InputOutput where it is explained how one can read and write Numpy arrays in human readable (ascii) format.
The document describes how one can use read_array/write_array if SciPy is installed, or how one can use load/save if Matplotlib is installed. When neither of these two packages is installed, one basically has no other choice then to improvise, so I also give here a few examples how one could do this.
Imho, there is something unsatisfactorily about this need to improvise. Ascii input/output of numpy arrays seems to me a very basic need. Even when one defines Numpy crudely as the N-dimensional array object, and Scipy as the science you can do with these array objects, then I would intuitively still expect that ascii input/output would belong to Numpy rather than to Scipy. There are Numpy support functions for binary format, and for pickled format, but strangely enough not really for ascii format. tofile() and fromfile() do not preserve the shape of a 2d array, and are in practice therefore hardly usable.
There may be a signficant fraction of Numpy users that do not need SciPy for their work, and have only Numpy installed. My guess is that the read_array and write_array functions have already been re-invented many many times by these users. Imho, I therefore think that Numpy deserves its own read_array/write_array method. Does anyone else have this feeling, or am I the only one? :o)
I think you are correct. I'd like to see better ascii input-output. That's why it's supported on a fundamental level in tofile and fromfile. SciPy's support for ascii reading and writing is rather slow as it has a lot of features. Something a little-less grandiose, but still able to read and write simple ascii tables would be a good thing to bring into NumPy. General-purpose parsing can be very difficult, but a simple parser for 2-d arrays would probably be very useful. On the other hand, I've found that even though it understands only one separator at this point, fromfile is still pretty useful for table processing as long as you know the shape of what you want. -Travis
Joris
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
participants (2)
-
joris@ster.kuleuven.ac.be
-
Travis Oliphant