I'm trying to reproduce the example given here: http://jkitchin.github.io/blog/2013/02/12/Nonlinear-curve-fitting-with-parameter-confidence-intervals/
So I imported the module like that:
from scipy.stats.distributions import t
But when I try to a simple
tval = t.ppf(1-alpha/2, dof)
I have the exception:
AttributeError: 'numpy.ndarray' object has no attribute 'ppf'
So t is a numpy.ndarray. But if I read the doc, it is supposed to be an object, with methods.
Do you have an idea about what's happening ?
It seems you may have overwritten the variable t with an array somewhere. What your error message means is that t is a numpy.ndarray which has no ppf method. The t you intended to import shouldn't be an ndarray but rather a distribution generator.
Either find where it became an array and use another name there, or import with better names.
For example, try changing your import line to this:
from scipy.stats import distrbutions as dists
and then change the problem line to:
tval = dists.t.ppf(1-alpha/2, dof)
Alternatively:
from scipy.stats.distributions import t as tdist
tval = tdist.ppf(1-alpha/2, dof)
Related
import mains
print(mains.hi())
import parsogv2
print(parsogv2.gets())
priliv = mains()/parsogv2()
I have this trouble 'module' object is not callable. I want to split the values I get in modules How to do it better ? Combine them into one module or can I do as I wanted in the code ?
If what you've been trying to do is divide the return values of mains.hi() and parsogv2.gets(), then what you should be doing is:
priliv = mains.hi()/parsogv2.gets()
The error you've been receiving, informing you that a module is not callable, is a result of your attempt to call the actual modules (mains and parsogv2) instead of the functions they contain (mains.hi and parsogv2.gets), which I assume is what you were going for.
works:
import sympy as sp
import pandas as pd
test = pd.DataFrame( {'greeting':['hey','hi','hello','howdy']} )
test1['greeting'].map(lambda x: sp.Set(*x).is_proper_subset( sp.Set(*x) ))
doesn't work:
import sympy as sp
import pandas as pd
test = pd.DataFrame( {'greeting':['hey','hi','hello','howdy']} )
test1['greeting'].map(lambda x: sp.Set('hi',).is_proper_subset( sp.Set(*x) ))```
i get:
AttributeError: 'str' object has no attribute 'args'
i've also tried with numbers on another dataframe:
test['triplets'].map(lambda x: sp.Set(*(813,)).is_proper_subset( sp.Set(*x) ))
and i get the same result.
https://docs.sympy.org/latest/modules/sets.html
class sympy.sets.sets.Set(*args)[source]¶
The base class for any kind of set.
ok...why is it working for each Series value when i pass it through lambda, but not when i write it manually
note: my end goal is to have this inside a for loop where the the iteration is passed into where i have 'hi'
From sympy's Set documentation:
class sympy.sets.sets.Set(*args)[source]¶
This is not meant to be used directly as a container of items. It does not behave like the builtin set; see FiniteSet for that.
The main problem is that is_proper_subset is meant for Interval type of "sets". It doesn't seem to handle simpler sets well, but gives a rather cryptic error message. When debugging, it often helps to reduce the problem as much as possible:
import sympy as sp
sp.Set(1, 2).is_proper_subset(sp.Set(1, 2, 3))
This raises the error AttributeError: 'int' object has no attribute 'args'.
Similarly:
sp.Set('a', 'b').is_proper_subset(sp.Set('a', 'b', 'c'))
Leads to AttributeError: 'str' object has no attribute 'args'.
The best solution to the original problem, is to use standard python functions.
i don't know what the deal is, i'm hoping there's an answer - but until then, i've resorted to this:
test1['greeting'].map(lambda x: set('hi').issubset(set(x)) and set('hi')!=set(x))
I am trying to solve an equation for r when given values for x and y. to do this I am using the solve ability of sympy. the code that I have is
import numpy as np
import matplotlib.pyplot as plt
from sympy import solve
from sympy import Symbol
from sympy import acos,sin
x=2
y=-2
r=Symbol("r",real=True)
solve(r(acos(1.0-(y/r)))-sin(acos(1.0-(y/r)))-x)
when I run the code it gives me the error
'Symbol' object is not callable
line 10, in <module>
solve(r(acos(1.0-(y/r)))-sin(acos(1.0-(y/r)))-x)
the reason I import numpy and matplotlib is that I will use them later in my code. Thanks for any help.
The error directs you toward what to look for: a Symbol that is being called. In Python syntax this is a Symbol followed by pair of parentheses with one or more arguments between them. You probably intended to multiply by r in the first argument of the expression:
>>> solve(r(acos(1.0-(y/r)))...
^__make that r*acos(1.0-(y/r))...
An editor that highlights matching parentheses (like the online editor of Python code at repl.it) can be helpful in these circumstances. Parentheses are either grouping or, when following a Python name, acting as the delimiters for the arguments being passed to a function.
I tried the follwing code and tried to read eseden from a nodeset. I get the following error as "Type error Field output object is not iterable".
Aravind
from odbAccess import *
from textRepr import *
from abaqusConstants import *
import odbAccess
odb=openOdb(path='python2d.odb')
NodesofInterest = odb.rootAssembly.instances['PART-1-1'].nodeSets['NODESET']
eseden=odb.steps['Step-1'].frames[1].fieldOutputs['ESEDEN'].getSubset(region=NodesofInterest)
for v in eseden:
print v
print (v.elementLabel,v.data)
The method getSubset called on fieldOutputs repository returns a FieldOutput object. That object contains a member values, which can be used to read values for a specific variable, 'ESEDEN' in your case.
Member values is actually a FieldValueArray with FieldValue objects, each with all the necessary information about data for a single node.
The reason you're getting an error is that 'FieldOutput' object is really not iterable, so to retrieve the actual information, you need to follow connections as I've just described.
To make this description somewhat more clear, here's a simple example using your code:
from odbAccess import *
from textRepr import *
from abaqusConstants import *
import odbAccess
odb=openOdb(path='python2d.odb')
NodesofInterest = odb.rootAssembly.instances['PART-1-1'].nodeSets['NODESET']
eseden=odb.steps['Step-1'].frames[1].fieldOutputs['ESEDEN'].getSubset(region=NodesofInterest)
# This kind of iteration should work since FieldValueArray is not
# a repository
for value in eseden.values:
# Should print node's label and corresponding value
print value.nodelabel, value.data
You can read more about this if you search for FieldOutput and FieldValue in the documentation. Unfortunately, I can't find a way to directly link any part of documentation separately.
There is one thing, that I do not understand.
Why does this
import scipy # happens with several other modules, too. I took scipy as an example now...
matrix = scipy.sparse.coo_matrix(some_params)
produce this error:
AttributeError: 'module' object has no attribute 'sparse'
This happens because the scipy module doesn't have any attribute named sparse. That attribute only gets defined when you import scipy.sparse.
Submodules don't automatically get imported when you just import scipy; you need to import them explicitly. The same holds for most packages, although a package can choose to import its own submodules if it wants to. (For example, if scipy/__init__.py included a statement import scipy.sparse, then the sparse submodule would be imported whenever you import scipy.)
Because you imported scipy, not sparse. Try from scipy import sparse?
AttributeError is raised when attribute of the object is not available.
An attribute reference is a primary followed by a period and a name:
attributeref ::= primary "." identifier
To return a list of valid attributes for that object, use dir(), e.g.:
dir(scipy)
So probably you need to do simply: import scipy.sparse
The default namespace in Python is "__main__". When you use import scipy, Python creates a separate namespace as your module name.
The rule in Pyhton is: when you want to call an attribute from another namespaces you have to use the fully qualified attribute name.