On Tue, Apr 28, 2009 at 12:29 PM, Alden <alden....@gmail.com> wrote:
>
> On two different computers running Ubuntu 9.04, I downloaded and built
> from source sage 3.4.1. I also downloaded scipy using the synaptic
> package manager. I am under the impression that python and scipy in
> sage lead completely separate lives from python and scipy outside
> sage. In normal python (i.e. running python from the command line),
> the following works fine:
This is correct.
> sage: import scipy.stats
> sage: scipy.stats.poisson.pmf(5,1)
When you type this, what get sent to Sage is the output of
sage: preparse('scipy.stats.poisson.pmf(5,1)')
'scipy.stats.poisson.pmf(Integer(5),Integer(1))'
Numpy/Scipy don't know how to deal with Sage's Integer class. You can
get around this in a number of ways:
1) Use the "r" notation for "raw" Python ints:
sage: preparse('scipy.stats.poisson.pmf(5r,1r)')
'scipy.stats.poisson.pmf(5,1)'
sage: scipy.stats.poisson.pmf(5r,1r)
array(0.00306566200976202)
2) Explicitly make ints:
sage: scipy.stats.poisson.pmf(int(5),int(1))
array(0.00306566200976202)
3) Turn off the preparser:
sage: preparser(False)
sage: scipy.stats.poisson.pmf(5,1)
array(0.00306566200976202)
sage: preparser(True)
4) Set Integer to be int (and RealNumber to be Float):
sage: Integer = int
sage: RealNumber = float
sage: scipy.stats.poisson.pmf(5,1)
array(0.00306566200976202)
--Mike
Mike's solution is right and my remark isn't. I had tested resetting
Integer by doing the following
in a notebook cell:
{{{
RealNumber=float; Integer=int
import scipy.stats
scipy.stats.poisson.pmf(5,1)
}}}
However, stupidly Integer=int gets evaluated after the constant 5 gets
factored out. This would have worked
{{{
RealNumber=float; Integer=int
}}}
{{{
import scipy.stats
scipy.stats.poisson.pmf(5,1)
}}}
We *really* need to patch scipy.stats so that this fixed...
-- William
>
>> In normal python (i.e. running python from the command line),
>> the following works fine:
>
> This will evidently get fixed when we upgrade the version of scipy
> included in Sage, which we
> hope to do soon.
Are you saying this is already fixed in scipy (i.e., a new scipy will
recognize sage numbers)?
Thanks,
Jason
--
Jason Grout