【发布时间】:2014-10-20 20:56:42
【问题描述】:
我正在使用 numpy 的 power 函数,并且收到一条警告消息。这是代码:
import numpy as np
def f(x, n):
factor = n / (1. + n)
exponent = 1. + (1. / n)
f1_x = factor * np.power(0.5, exponent) - np.power(0.5 - x, exponent)
f2_x = factor * np.power(0.5, exponent) - np.power(x - 0.5, exponent)
return np.where((0 <= x) & (x <= 0.5), f1_x, f2_x)
fv = np.vectorize(f, otypes='f')
x = np.linspace(0., 1., 20)
print(fv(x, 0.23))
这是警告信息:
E:\ProgramasPython3\LibroCientifico\partesvectorizada.py:8: RuntimeWarning: power f2_x = factor * 中遇到的无效值 np.power(0.5, exponent) - np.power(x - 0.5, exponent) E:\ProgramasPython3\LibroCientifico\partesvectorizada.py:7: RuntimeWarning: power f1_x = factor * 中遇到的无效值 np.power(0.5, exponent) - np.power(0.5 - x, exponent) [-0.0199636 -0.00895462 -0.0023446 0.00136486 0.003271 0.00414007 0.00447386 0.00457215 0.00459036 0.00459162 0.00459162 0.00459036 0.00457215 0.00447386 0.00414007 0.003271 0.00136486 -0.0023446 -0.00895462 -0.0199636]
我不知道什么是无效值。而且我不知道如何指定numpy函数f2_x仅对> 0.5和
【问题讨论】:
-
对我来说运行良好 - Python 3.4.1、numpy 1.9.0、Win8
标签: python-3.x numpy