Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:不支持**或pow()的操作数类型:';列表';和';int';。plt.plot_Python - Fatal编程技术网

Python TypeError:不支持**或pow()的操作数类型:';列表';和';int';。plt.plot

Python TypeError:不支持**或pow()的操作数类型:';列表';和';int';。plt.plot,python,Python,当我编写以下代码时,我得到以下错误。 我做错了什么 def f(t): return np.sin(t**2) n = 20 # number of points for Riemann integration a = 0; b = 2 P = np.linspace(a, b, n) # Standard partition constant width dt = (b-a)/n T = [np.random.rand()*dt + p for p in P[:-1]] # R

当我编写以下代码时,我得到以下错误。 我做错了什么

def f(t):
    return np.sin(t**2)

n = 20  # number of points for Riemann integration
a = 0; b = 2
P = np.linspace(a, b, n)  # Standard partition constant width
dt = (b-a)/n
T = [np.random.rand()*dt + p for p in P[:-1]]  # Randomly chosen point
再做几件事,然后: 最后我得到以下错误:

    Traceback (most recent call last):
    File "riman.py", line 35, in <module>
    plt.plot(T, f(T), '.', markersize=10)
    File "riman.py", line 11, in f
    return np.sin(t**2)
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
回溯(最近一次呼叫最后一次):
文件“riman.py”,第35行,在
plt.绘图(T,f(T),“.”,markersize=10)
文件“riman.py”,第11行,在f中
返回np.sin(t**2)
TypeError:不支持**或pow()的操作数类型:'list'和'int'

错误消息是不言自明的–没有为内置的
列表
类型定义电源操作员
**

但是,它们是为
np.array
s定义的:

>>> np.array(range(5))**2
array([ 0,  1,  4,  9, 16])
修正:


t
是一个列表……我该怎么做?@BatelCarmona点击左侧的灰色勾号,就在分数下面
>>> np.array(range(5))**2
array([ 0,  1,  4,  9, 16])
T = np.array([np.random.rand()*dt + p for p in P[:-1]])