为什么NumPy和SciPy具有许多相同的功能?我该选哪个? [英] Why do NumPy and SciPy have a lot of the same functions? Which should I prefer?

查看:191
本文介绍了为什么NumPy和SciPy具有许多相同的功能?我该选哪个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
scipy和numpy之间的关系

Possible Duplicate:
Relationship between scipy and numpy

例如,NumPy具有窗口函数 blackmanhamminghanningkaiser,而SciPy具有这些以及其他,但它们似乎产生相同的输出.

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具有numpy.fft.fft2(a, s=None, axes=(-2, -1)).

SciPy具有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?

推荐答案

来自

在理想世界中,NumPy除了数组数据类型和最基本的数据外,将不包含任何其他内容 操作:索引,排序,整形,基本的元素函数等.全部 数字代码将驻留在SciPy中.但是,NumPy的重要目标之一是 兼容性,因此NumPy尝试保留其任一版本支持的所有功能 前辈.因此,NumPy包含一些线性代数函数,即使这些更多 正确地属于SciPy.无论如何,SciPy都包含更全功能的 线性代数模块,以及许多其他数值算法.如果你在做 使用python进行科学计算时,您可能应该同时安装NumPy和SciPy.大多数新功能都属于SciPy,而不是NumPy.

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.

是的,重复项是为了向后兼容.通常,它们给出相同的结果.但是,正如FAQ所述,新功能通常是在SciPy中实现的,但不一定是NumPy.这包括错误修复.例如,我发现numpy.linalg.eig对于复杂矩阵返回了错误的特征值,而scipy.linalg.eig返回了正确的特征值.

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.

通常,我更喜欢FAQ中的理想世界"场景:我将NumPy用于基本数组操作,将SciPy用于所有线性代数.这样,我就不会遇到任何意外.

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.

这篇关于为什么NumPy和SciPy具有许多相同的功能?我该选哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆