numpy.power(x1,x2)不等于x1 ** x2

时间:2017-04-04 11:47:55

标签: python numpy

我发现numpy中power函数的特殊之处与我认为的一般python类型处理哲学不一致。

我假设numpy.power(x1, x2)的输出在数值上等于x1**x2,但事实证明x2 < 0不是这种情况。如下图所示:

In [320]: 2**-8
Out[320]: 0.00390625

In [321]: np.power(2, -8)
Out[321]: 0

In [322]: np.power(2., -8)
Out[322]: 0.00390625

虽然哲学被教导为python解释器在必要时改变类型(例如,1/3 = 0.333,而不是0),numpy.power函数似乎已经逃脱了这种哲学变化。

或者有没有理由为什么要这样做...... ???

亲切的问候

0 个答案:

没有答案
相关问题