Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Error - No module named numpyio

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??

like image 542
David Avatar asked Feb 20 '23 11:02

David


2 Answers

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").

like image 175
Chris Avatar answered Feb 23 '23 00:02

Chris


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.

like image 37
geodata Avatar answered Feb 23 '23 00:02

geodata