SciPy和NumPy之间的关系

SciPy和NumPy之间的关系,第1张

SciPy和NumPy之间的关系

上次我检查它时,scipy

__init__
方法执行

from numpy import *

以便在导入scipy模块时将整个numpy命名空间包含到scipy中。

log10
您描述的行为很有趣,因为 两个 版本都来自numpy。一个是a
ufunc
,另一个是
numpy.lib
功能。为什么scipy偏爱库函数而不是
ufunc
,我不知道该怎么办。


编辑:事实上,我可以回答这个

log10
问题。在scipy
__init__
方法中,我看到以下内容:

# import numpy symbols to scipy name spaceimport numpy as _numfrom numpy import oldnumericfrom numpy import *from numpy.random import rand, randnfrom numpy.fft import fft, ifftfrom numpy.lib.scimath import *

log10
您获得scipy的功能来自
numpy.lib.scimath
。查看该代码,它说:

"""Wrapper functions to more user-friendly calling of certain math functionswhose output data-type is different than the input data-type in certaindomains of the input.For example, for functions like log() with branch cuts, the versions in thismodule provide the mathematically valid answers in the complex plane:>>> import math>>> from numpy.lib import scimath>>> scimath.log(-math.exp(1)) == (1+1j*math.pi)TrueSimilarly, sqrt(), other base logarithms, power() and trig functions arecorrectly handled.  See their respective docstrings for specific examples."""

看来模块覆盖了基础numpy的ufuncs

sqrt
log
log2
logn
log10
power
arccos
arcsin
,和
arctanh
。这就解释了您所看到的行为。这样做的根本设计原因可能埋在某个地方的邮件列表中。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5623446.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存