Anyone know how to solve this error?
Exception Type: ImportError
Exception Value: No module named numpyio
See my python code, my imports:
from scipy.io.numpyio import fwrite, fread
Can you help me??
This is becase the scipy.io.numpyio
module was removed sometime aftey SciPy 0.7 (see, for example, this thread). From the SciPy Input/Output Cookbook page you can instead use the functions numpy.fromfile
and numpy.nadarray.tofile
(see under the heading "Raw binary").
While the numpy.ndarray.fromfile()
allows you to specify the binary format to read (e.g. 'f' for float), the .tofile()
function doesn't have such binary options. This is a highly inconvenient inconsistency for those of us who need to write binary files in a specific format for other software to read. Unfortunately this problem seems to be ignored by the development community as there seems to be no open ticket.
I have created a simple replacement function using the array module. The basic code goes something like this:
def fwrite(filename, formatstring, ndarray):
arr = array.array(formatstring, ndarray.flatten())
f = open(filename, 'w')
arr.tofile(f)
f.close()
So far that seems to work. Obviously this could/should be embellished with error checkes etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With