I've been trying to get started with scipy, but the package is giving me some problems. The tutorial leans heavily on scipy.io, but when I import scypi and try to use scipy.io, I get errors:
In [1]: import scipy In [2]: help(scipy.io) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/chris/dev/scipy/<ipython-input-2-ef060398b31c> in <module>() ----> 1 help(scipy.io) AttributeError: 'module' object has no attribute 'io'
I've run system updates and I uninstalled scipy then installed it again.
Interestingly enough, I can import the module this way:
In [1]: import scipy.io
But then when I try to use it, I get an error as soon as I use a method:
In [2]: arr = scipy.array([[1.0,2.0],[3.0,4.0],[5.0,6.0]]) In [3]: outFile = file('tmpdata1.txt', 'w') In [4]: scipy.io.write_array(outFile, arr) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/chris/dev/scipy/<ipython-input-4-46d22e4ff485> in <module>() ----> 1 scipy.io.write_array(outFile, arr) AttributeError: 'module' object has no attribute 'write_array'
I'm sure I'm missing something embarrassingly basic, but I've not been able to find an answer to this problem on Google or in the stackoverflow archives.
Install SciPy using the pip command Python consists of pip command which is an official package installer. It is a package manager, we can install, delete, or update any package. We need to install pip for using the pip command. Once the requirement is satisfied we can use the pip command in terminal.
We can install the SciPy library by using pip command; run the following command in the terminal: pip install scipy.
SciPy is an open-source Python library which is used to solve scientific and mathematical problems. It is built on the NumPy extension and allows the user to manipulate and visualize data with a wide range of high-level commands.
SciPy is a scientific computation library that uses NumPy underneath. SciPy stands for Scientific Python. It provides more utility functions for optimization, stats and signal processing. Like NumPy, SciPy is open source so we can use it freely. SciPy was created by NumPy's creator Travis Olliphant.
Two things here. First, you cannot in general access a module in a package by doing import package
and then trying to access package.module
. You often have to do what you did, import package.module
, or (if you don't want to type package.module
all the time, you can do from package import module
. So you can also do from scipy import io
.
Second, the scipy.io
module does not provide a write_array
function. It looks like maybe it used to, but they got rid of it. You may be looking at an outdated tutorial. (What tutorial are you using?) Googling around, it seems they suggest to use numpy's savetxt
function instead, so you might want to look into that.
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