David
David

Reputation: 199

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

Upvotes: 4

Views: 2791

Answers (3)

geodata
geodata

Reputation: 140

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.

Upvotes: 3

Chris
Chris

Reputation: 46316

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

Upvotes: 4

Christian Witts
Christian Witts

Reputation: 11585

From the archives:

The I/O functions for numpy arrays have been moved to numpy where it made, or removed when they provided duplicate functionality. Use numpy.load and numpy.save for reading writing arrays in numpy's own .npy format, loadtxt/savetxt for ascii.

Upvotes: 1

Related Questions