From: Chris B. <chr...@ho...> - 2001-08-07 20:07:51
|
Hung Jung Lu wrote: > Arrays have a method called tostring() which generates > the binary data. Is there an inverse function to that? > That is, generating an array from the binary data > string? As you suspected, there is such a thing, and it is called (surprise): fromstring(). It is a function, rather than a method, as it is a constructor for an array. To get data from a file, you have to get it into a string first, so I use: M = fromstring(file.read(),Float) This makes a rank -1 array. You might have to reshape it. Note that you end up creating a Python string of the data first, and then a NumPy array from that. This doesn't really cost that much, but it can be an issue with huge data sets. I wish there was a fromfile() function. I may get around to writing it one day. -Chris -- Christopher Barker, Ph.D. Chr...@ho... --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ |