[SciPy-User] Order of numpy orperations is not equal to logic (and also octave)?
josef.pktd@gmai...
josef.pktd@gmai...
Sun Oct 31 15:39:55 CDT 2010
On Sun, Oct 31, 2010 at 4:30 PM, Oz Nahum Tiram <nahumoz@gmail.com> wrote:
> Continuing this subject, I have a feeling that numpy behaves in very
> un-intuitive way for me.
> Here is an example that someone gave me in Stackoverflow.com:
>
>>>> import numpy as np
>>>> a=np.array([1,0])
>>>> b=np.array([-1,1])
>
>>>> np.sum(a)/np.sum(b)
> 0
>>>> np.sum(a)/b
> array([-1, 1])
>>>> np.sum(a)/0
> 0
That's integer division not floating point division, something to get
used to in python below version 3, or switch to from __future__ import
division (???)
It's python and not numpy specific.
Josef
>
>
> Octave warns when dividing by zero:
> octave:1> a=[1,0]
> a =
>
> 1 0
>
> octave:2> b=[-1,1]
> b =
>
> -1 1
>
> octave:3> sum(a)/sum(b)
> warning: division by zero
> ans = Inf
> octave:4> sum(a)./sum(b)
> warning: division by zero
> ans = Inf
> octave:5> sum(a)./b
> ans =
>
> -1 1
>
>
> I think this is very important that these differences are broad-casted to
> new comers from matlab/octave to python and numpy.
> I work interchangeably with both, and this is quite tricky...
>
>
> --
> Oz Nahum
> Graduate Student
> Zentrum für Angewandte Geologie
> Universität Tübingen
>
> ---
>
> Imagine there's no countries
> it isn't hard to do
> Nothing to kill or die for
> And no religion too
> Imagine all the people
> Living life in peace
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
More information about the SciPy-User
mailing list