我使用numpy的電源功能,並且我正在獲取警告消息。這是代碼:運行時警告使用Numpy電源
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:在功率f2_x =因數遇到無效值* np.power(0.5,exponent) - np.power(x - 0.5,指數) E:\ ProgramasPython3 \ LibroCientifico \ partesvectorizada.py:7: RuntimeWarning:電源遇到的無效值f1_x =因子* np.power (0.5,指數) - np.power(0.5 - x,指數)[-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和< = 1.0之間的值。 謝謝
它對我來說運行良好 - Python 3.4.1,numpy 1.9.0,Win8 – MattDMo 2014-10-20 21:08:31