Having a problem in scipy.stats fro importing describe() - python

In Scipy documentation, it clearly says for using statistics(especially for a short description of an array):
Import scipy
scipy.stats.describe(a, axis=0, ddof=1, bias=True, nan_policy='propagate')
But I get the AttributeError:
module 'scipy' has no attribute 'stats'
then in another part of the documentation, it says :
from scipy import stats
which works fine for me. Actually, I don't get the exact difference between . and from ...... import ...... and why the first one doesn't work.
Thank you so much for your help. I would appreciate it if you guys can provide me some links too.

Related

rdkit module functions in Chem.Descriptors not working and unsure why?

I'm new to using rdkit but can't find any forum posts online addressing this but I've been trying to use the functions in rdkit.Chem.Descriptors as follows:
from rdkit import Chem
mol = Chem.MolFromSmiles('CC')
Descriptors.MolWt(mol)
this should just return the molecular weight = 30.07 of the molecule simply and I took this from the documentation but it just gives me an error saying:
NameError: name 'Descriptors' is not defined
I have no idea why - I tried changing versions but this has made no difference. It seems to be an error inherent to all functions in the Descriptor class.
I've also tried explicitly importing the Descriptor submodule/class and this doesn't work either.
from rdkit.Chem import Descriptors
is the correct way to import module for this code to work

skimage feature module missing documented attributes

I'm running one of the examples from skimage documentation and struggling to find either the multiscale_basic_features referenced there as an attribute of the skimage.feature module or its current equivalent. Does anyone know what I can substitute it with in the following segment of their code?:
features_func = partial(feature.multiscale_basic_features, intensity=True, edges=False, texture=True,
sigma_min=sigma_min, sigma_max=sigma_max,
multichannel=True)
You probably need to upgrade your scikit-image version. That function was only added in 0.18.1.

solve_ivp Error: "missing 2 required positional arguments:"

The function that I am using for solve_ivp is defined as:
def ydot(t,y,kappa4,kappa16):
Upon using solve_ivp as below:
sol=solve_ivp(ydot,[0,10],initial_condition(),args=(50,100))
I get the following error:
ydot() missing 2 required positional arguments: 'kappa4' and 'kappa16'
I am not able debug the code even though I have defined the function ydot the way scipy documentation for solve_ivp defines (https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html)
There's even an example in the end of the documentation that demonstrates the passing of arguments implemented in the same way as I have done.
I believe the problem is somewhere in the two above pieces of the code I have provided from an otherwise long code.
I was able to replicate the error with scipy 1.1.0 .
Upgrading scipy to the latest version via cmd (pip install scipy==1.4.1) solved that error message for me.
Then the minimal reproducible example gave another error:
TypeError: ydot() argument after * must be an iterable, not int
Which was solved by the solution given by Tejas. The full working minimal script is hence:
from scipy.integrate import solve_ivp
def ydot(t,y,a): return -a*y
sol=solve_ivp(ydot,[0,10],[5],args=(8,))
print(sol.y)
I had faced the same issue recently.
But the great Warren Weckesser
helped me out.
Change
args=(10)
to
args=(10,)
and your MWE will work fine.
This happens because of tuples with a single element.
For reference see pg 30 of Python tutorial pdf (Release 3.5.1) on python.org

module 'scipy.optimize' has no attribute 'anneal'

I tried to run following program of using python 3.5.1.
from scipy import optimize
optimize.anneal(f, input_vector0, lower = 0, upper = 2*np.pi)
I got the following error message:
AttributeError: module 'scipy.optimize' has no attribute 'anneal'.
Can anybody tell me what should I do to fix this? i really appreciate it !
The problem is that it is removed in 0.16 and higher.
Replace anneal with basinhopping.
refer to link

Random Gaussian issues

I'm trying to generate a random.gauss numbers but I have message error. Here is my code:
import sys,os
import numpy as np
from random import gauss
previous_value1=1018.163072765074389
previous_value2=0.004264112033664
alea_var_n=random.gauss(1,2)
alea_var_tau=random.gauss(1,2)
new_var_n= previous_value1*(1.0+alea_var_n)
new_var_tau=previous_value2*(1.0+alea_var_tau)
print 'new_var_n',new_var_n
print 'new_var_tau',new_var_tau
I got this error:
Traceback (most recent call last):
File "lolo.py", line 15, in <module>
alea_var_n=random.gauss(1,2)
AttributeError: 'builtin_function_or_method' object has no attribute 'gauss'
Someone know what's wrong, I'm a newbye with python. Or is it a numpy version problem.
For a faster option, see Benjamin Bannier's solution (which I gave a +1 to). Your present code that you posted will not work for the following reason: your import statement
from random import gauss
adds gauss to your namespace but not random. You need to do this instead:
alea_var_n = gauss(1, 2)
The error in your post, however, is not the error you should get when you run the code that you have posted above. Instead, you will get the following error:
NameError: name 'random' is not defined
Are you sure you have posted the code that generated that error? Or have you somehow included the wrong error in your post?
Justin Barber shows you an immediate solution for your problem.
Since you are using NumPy you could however use their generators as well since they appear to be significantly faster (about a factor 5-7 on my machine), e.g.
alea_var_n = np.random.normal(1, 2)

Categories

Resources