Use of scipy special functions from sage

46 views
Skip to first unread message

shahab

unread,
Feb 6, 2008, 5:44:20 PM2/6/08
to sage-support
Hello,

Anybody has any suggestions as how to figure a solutions for the
problem below?

In trying to call functions in scipy.stats where it calls
scipy.special functions, I get the error seen below. There are no
problems calling these functions from !python.
I assume that within sage, there is a problem coercing sage objects
into python types for these special functions. And since the betainc
function is called from another scipy module, I can't explicitly
declare the variable types.

Any suggestions?

Thanks

Shahab


sage: from scipy import stats
sage: stats.ttest_ind(list([1,2,3,4,5]),list([2,3,4,5,.6]))
---------------------------------------------------------------------------
<type 'exceptions.TypeError'> Traceback (most recent call
last)

/home/jars/Desktop/sage/<ipython console> in <module>()

/home/jars/Desktop/sage/local/lib/python2.5/site-packages/scipy/stats/
stats.py in ttest_ind(a, b, axis)
1706 t = (x1-x2)/np.sqrt(svar*(1.0/n1 + 1.0/n2)) # N-D
COMPUTATION HERE!!!!!!
1707 t = np.where(zerodivproblem, 1.0, t) # replace
NaN t-values with 1.0
-> 1708 probs = betai(0.5*df,0.5,float(df)/(df+t*t))
1709
1710 if not np.isscalar(t):

/home/jars/Desktop/sage/local/lib/python2.5/site-packages/scipy/stats/
stats.py in betai(a, b, x)
2014 x = np.asarray(x)
2015 x = np.where(x < 1.0, x, 1.0) # if x > 1 then return 1.0
-> 2016 return special.betainc(a, b, x)
2017
2018 #####################################

<type 'exceptions.TypeError'>: function not supported for these types,
and can't coerce safely to supported types
sage:

William Stein

unread,
Feb 6, 2008, 6:05:22 PM2/6/08
to sage-s...@googlegroups.com
On Feb 6, 2008 2:44 PM, shahab <geno...@gmail.com> wrote:
>
> Hello,
>
> Anybody has any suggestions as how to figure a solutions for the
> problem below?
>
> In trying to call functions in scipy.stats where it calls
> scipy.special functions, I get the error seen below. There are no

I was using exactly the same functionality in sage this week too.
See this faq entry I just added:

http://wiki.sagemath.org/faq

* QUESTION: I'm using scipy or cvxopt or numpy from Sage and get
type errors, e.g., "TypeError: function not supported for these types,
and can't coerce safely to supported types."
* ANSWER: Redefine RealNumber to change the behavior of the Sage
preparser, so decimal literals are floats instead of Sage arbitrary
precision real numbers, for example:

sage: from scipy import stats

sage: RealNumber=float


sage: stats.ttest_ind(list([1,2,3,4,5]),list([2,3,4,5,.6]))

(array(0.076752955645333687), 0.940704902474)

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Reply all
Reply to author
Forward
0 new messages