Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do NumPy and SciPy have a lot of the same functions? Which should I prefer? [duplicate]

Possible Duplicate:
Relationship between scipy and numpy

For instance, NumPy has window functions bartlett, blackman, hamming, hanning, kaiser, while SciPy has these and several more, but they seem to produce identical output.

NumPy has numpy.fft.fft2(a, s=None, axes=(-2, -1)).

SciPy has scipy.fftpack.fft2(x, shape=None, axes=(-2, -1), overwrite_x=0).

Why are there duplicates? Just for backwards compatibility? If so, why are they defined differently in different places? Which should I prefer when writing something new?

like image 551
endolith Avatar asked May 26 '12 12:05

endolith


People also ask

Is NumPy and SciPy the same?

NumPy and SciPy both are very important libraries in Python. They have a wide range of functions and contrasting operations. NumPy is short for Numerical Python while SciPy is an abbreviation of Scientific Python. Both are modules of Python and are used to perform various operations with the data.

Which is better SciPy or NumPy?

Functional differences − NumPy has a faster processing speed than SciPy. The functions defined in NumPy library are not in depth whereas SciPy library consists of detailed versions of the functions.

Is SciPy dependent on NumPy?

While NumPy on its own offers limited functions for data analysis, many other libraries that are key to analysis—such as SciPy, matplotlib, and pandas are heavily dependent on NumPy. SciPy, for instance, offers advanced mathematical functions built on top of NumPy's array data structure, ndarray .

Are you aware of how NumPy and SciPy are dissimilar Could you name a couple of differences?

The FFTs of SciPy and NumPy are different. SciPy uses the Fortran library FFTPACK, hence the name scipy. fftpack. NumPy uses a C library called fftpack_lite; it has fewer functions and only supports double precision in NumPy.


1 Answers

From the SciPy FAQ:

In an ideal world, NumPy would contain nothing but the array data type and the most basic operations: indexing, sorting, reshaping, basic elementwise functions, et cetera. All numerical code would reside in SciPy. However, one of NumPy’s important goals is compatibility, so NumPy tries to retain all features supported by either of its predecessors. Thus NumPy contains some linear algebra functions, even though these more properly belong in SciPy. In any case, SciPy contains more fully-featured versions of the linear algebra modules, as well as many other numerical algorithms. If you are doing scientific computing with python, you should probably install both NumPy and SciPy. Most new > features belong in SciPy rather than NumPy.

So yes, the duplicates are for backwards compatibility. In general, they give the same result. However, as the FAQ states, new features are usually implemented into SciPy, but not necessarily NumPy. This includes bug fixes. I have found, for example, that numpy.linalg.eig returned incorrect eigenvalues for a complex matrix, whereas scipy.linalg.eig returned correct ones.

In general, I prefer stick with the "ideal world" scenario from the FAQ: I use NumPy for the basic array manipulations, and SciPy for all my linear algebra. This way I don't run into any surprises.

like image 66
SethMMorton Avatar answered Nov 14 '22 20:11

SethMMorton