[Numpy-discussion] numpy or scipy ?

Anne Archibald peridot.faceted@gmail....
Tue Sep 9 01:45:11 CDT 2008


2008/9/8 xiaojf <FDU.xiaojf@gmail.com>:
> Hi all,
>
> I'm trying to replace matlab with python in my daily work and I have
> several problems now.
>
> 1) Which one should I use, numpy or scipy ? I found that numpy and
> scipy have many overlap functions and modules, such as numpy.linalg
> and scipy.linaly.
>
> Maybe I should use numpy in some occasions and use scipy in the other
> occasions?

In addition to what others have said - numpy is basic array
operations, scipy is any sophisticated calculations - I should point
out that there are many functions from numpy that are, for historical
reasons, simply reexported as names in scipy. For example,

In [7]: scipy.sin == numpy.sin
Out[7]: True

These functions will obviously behave identically. However, some
functions provide extended versions in scipy:

In [8]: numpy.sqrt(-1.)
Out[8]: nan

In [9]: scipy.sqrt(-1.)
Out[9]: 1j

The rule here is that scipy has the more "scientifically-correct"
versions, while numpy has the more efficient and less surprising
versions (notice that scipy.sqrt must return a complex array if any
element of its input is real but negative, so its return type depends
on the input value...)

For the most part, though, scipy has tools and algorithms you might
need for numerical calculations - a good rule of thumb is that it has
tools to solve most of the problems described in the "Numerical
Recipes" books - while numpy is a simple array library.

Anne


More information about the Numpy-discussion mailing list