I'm getting the error mentioned in the title. I have all of the following three imports in my code:
import scipy as sc
import scipy.stats
from scipy import stats
But still get the error. I'm sure it has something to do with the version, but can't figure out either how to make it work or a workaround for "nanmean". Any suggestions would be appreciated.
nanmean was a deprecated function that was removed from scipy.stats in version 0.18.0. You will have to either use an older version of SciPy or use the equivalent function from NumPy.
from numpy import nanmean
nanmean is also available from scipy module itself, so this might work if you replace
from scipy.stats import nanmean
with
from scipy import nanmean
Related
I have some python code which uses function scipy.integrate.simpson
So for example I import scipy using import scipy.integrate as scp_int and then use it in following way:
vol_r = scp_int.simpson(f_integrand_r,dx=_dx1,axis=0)
I get this error
vol_r = scp_int.simpson(f_integrand_r,dx=_dx1,axis=0)
AttributeError: module 'scipy.integrate' has no attribute 'simpson'`
I have made sure that I have scipy package installed, using pip install scipy, and I have restarted computer. I don't know why is this happening? Can someone give the reason or help me solve this issue?
I suspect you are using version 1.5 (or an older version) of SciPy.
If you don't know which version you have installed, you can check with
import scipy
print(scipy.__version__)
simpson was added in 1.6.0; it is the new name for the old function called simps. If you can't upgrade, you should be able to use simps instead of simpson.
I have this code from scikit docs:
import numpy as np
np.random.seed(1)
I understand what this code does semantically, but I cannot understand what this code actually calls.
Ok, numpy is a name of python module and np is just an alias for that. But what is np.random? Is it module inside of another module?
I found source code on GitHub and random is just a folder inside of numpy directory. So numpy should be a package, not a module?
Numpy is a package, that contains module random which contains method seed.
I have imported scipy by this command in pycharm:
import scipy as sp
but as I want to use it in this way for example:
a=sp.special.factorial(5)
I receive an error related to module attribute and I have to import scipy in below way only, to get no error:
from scipy import special
but in another IDE like Spyder both commands runs with no error.
I use anaconda as interpretor in pycharm.
I am not familiar with Spyder. Perhaps they did something extra. But the official way of doing is you have to import scipy.special serapately.
import scipy
help(scipy) # it will give the following help message.
Help on package scipy:
NAME
scipy
DESCRIPTION
SciPy: A scientific computing package for Python
================================================
Documentation is available in the docstrings and
online at http://docs.scipy.org.
Contents
--------
SciPy imports all the functions from the NumPy namespace, and in
addition provides:
Subpackages
-----------
Using any of these subpackages requires an explicit import. For example,
``import scipy.cluster``.
I need to import a module from python 3.3 on Win7.
In Eclipse++PyDev, I cannot import stats from scipy
from scipy import stats
But, I can do it in iPython.
Alos, I have installed ipython and can do it in ipython by
from scipy.stats import rv_discrete
But, I need to do it in Eclipse where I have added python, numpy and scipy in it.
But, Eclipse tell me that
from scipy.stats import rv_discrete
error:
Unresolved import: rv_discrete
Import redefinition: rv_discrete
Unused import: rv_discrete
Any help would be really appreciated.
Thanks !
I thought that the code in the python-inverse-of-a-matrix was extremely interesting, particularly since I have used numpy for several years in computations that involve matrices. I was disappointed as the 2 imports from numpy failed. Here are the imports:
from numpy import matrix
from numpy import linalg
Neither matrix nor linalg were found in the numpy package. Clearly I miss something that is quite obvious (not for me, though :) ).
I use Linux (kubuntu) and downloaded the numpy package as a debian package. Are there other packages for "matrix" and for "linalg", if so, what are they?
Thank you in anticipation,
OldAl.
Most likely, you have a numpy.py or numpy.pyc file in your local directory... and python is finding it and importing it instead of the numpy package you expect.
Try this before importing.
import numpy
print(numpy.__file__)
You'll probably find that numpy.__file__ is pointing not to the numpy package, but to something you did not intend to import.
In general, it's a good idea to name your own modules with different names from known/popular packages.
SOLVED
The deb package numpy simply does not have the matrix and linalg sub-packages.
In ubuntu or kubuntu one needs to import scipy as well. Scipy expands the name space of numpy and adds matrix and linalg packages.
OldAl.