[SciPy-user] diff function, different from MatLab ...
Bill Baxter
wbaxter at gmail.com
Wed May 9 15:01:55 EDT 2007
On 5/9/07, Stef Mientki <s.mientki at ru.nl> wrote:
> hi Matthieu,
>
> Matthieu Brucher wrote:
> > Hi,
> >
> > I suppose that if s is a boolean array, diff is a boolean array as
> > well. Matlab works on doubles every time, not numpy, and your result
> > is coherent in a boolean algebra.
> I guess you're right,
>
> and also integer is not "upsized" to float: 5/3 = 1
> (but I believe that's a still a discussion for the Python 3 ;-)
>
> on the other hand, some functions do upsize the result
> sqrt(4) = 2.0
> sqrt(-4) = 2j
>
> I think I've just to familiarize with this ;-)
Well the rule in NumPy as I understand it is basically never to do
automatic upcasts. The above is not the behavior of NumPy for
sqrt(-4). That seems to be SciPy only. I'm not sure what SciPy's
rules are, but I thought they were the same as NumPy till seeing your
sqrt example.
In [43]: npy.sqrt(-1)
Warning: invalid value encountered in sqrt
--bb
More information about the SciPy-User
mailing list