これは、プロッタにレンジ機能によって生成されたいくつかの浮動小数点値を渡す私のコードです:のpython 3.4はTypeError:単項+に悪いオペランドのタイプ:「ジェネレータ」
import numpy as np
import matplotlib.pyplot as plt
gK_inf = 20.70
gK_0 = 0.01
tauN = 0.915 + 0.037
def graph(formula, t_range):
t = np.array(t_range)
gK = formula(t) # <- note now we're calling the function 'formula' with x
plt.plot(t, gK)
plt.xlabel(r"$g_K$")
plt.ylabel(r"$\frac{P_{i}}{P_{o}}$")
plt.legend([r"$\frac{P_{i}}{P_{o}}$"])
annotation_string = r"$E=0$"
plt.text(0.97,0.8, annotation_string, bbox=dict(facecolor='red', alpha=0.5),
transform=plt.gca().transAxes, va = "top", ha="right")
plt.show()
def my_formula(t):
return np.power((np.power(gK_inf,0.25))*((np.power(gK_inf,0.25)-np.power(gK_0,0.25))*np.exp(-t/tauN)),4)
def frange(x, y, jump):
while x < y:
yield x
x += jump
graph(my_formula, frange(0,11e-3,1e-3))
そして、これがスローエラーです:
> gK = formula(t) # <- note now we're calling the function 'formula'
> with x
> File "F:\Eclipse\my_test\gK", line 26, in my_formula
> return np.power((np.power(gK_inf,0.25))*((np.power(gK_inf,0.25)-np.power(gK_0,0.25))*np.exp(-t/tauN)),4)
> TypeError: bad operand type for unary -: 'generator'
お願いします。
浮動小数点範囲が必要な場合は、numpy.arangeまたは多分['numpy.linspace'](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html)を使用します。 #numpy.linspace) –