上次我检查过,scipy__init__
方法执行一个
from numpy import *
以便在导入 scipy 模块时将整个 numpy 命名空间包含到 scipy 中。
The log10
你所描述的行为很有趣,因为both版本来自 numpy。一个是一个ufunc
,另一个是numpy.lib
功能。为什么 scipy 更喜欢库函数而不是ufunc
,我脑子里不知道。
编辑:事实上,我可以回答log10
问题。在 scipy 中查找__init__
方法我看到这个:
# Import numpy symbols to scipy name space
import numpy as _num
from numpy import oldnumeric
from numpy import *
from numpy.random import rand, randn
from numpy.fft import fft, ifft
from numpy.lib.scimath import *
The log10
你在 scipy 中得到的函数来自numpy.lib.scimath
。看看该代码,它说:
"""
Wrapper functions to more user-friendly calling of certain math functions
whose output data-type is different than the input data-type in certain
domains of the input.
For example, for functions like log() with branch cuts, the versions in this
module 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)
True
Similarly, sqrt(), other base logarithms, power() and trig functions are
correctly handled. See their respective docstrings for specific examples.
"""
似乎该模块覆盖了基本 numpy ufuncssqrt
, log
, log2
, logn
, log10
, power
, arccos
, arcsin
, and arctanh
。这解释了您所看到的行为。这样做的根本设计原因可能隐藏在某处的邮件列表帖子中。