积分密度图 . TypeError:只能将length-1数组转换为Python标量

所以我试图让这个密度图适用于给定的积分 . 不知道我错过了什么但是我收到了这个错误 .

回溯:runfile('F:/ PHY 281 / Homework / Set 4 / tyest3.py',wdir ='F:/ PHY 281 / Homework / Set 4')Traceback(最近一次调用最后一次):文件“”,行1,在runfile中('F:/ PHY 281 / Homework / Set 4 / tyest3.py',wdir ='F:/ PHY 281 / Homework / Set 4')文件“E:\ Programs \ Anaconda \ lib \ site- packages \ spyder \ utils \ site \ sitecustomize.py“,第710行,在runfile execfile(文件名,命名空间)文件”E:\ Programs \ Anaconda \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py“,第101行,在execfile exec(compile(f.read(),filename,'exec'),namespace)文件“F:/ PHY 281 / Homework / Set 4 / tyest3.py”,第27行,gb = quad( Jm,0,1e-6)[0]文件“E:\ Programs \ Anaconda \ lib \ site-packages \ scipy \ integrate \ quadpack.py”,第323行,四点)文件“E:\ Programs \ Anaconda \ lib \ site-packages \ scipy \ integrate \ quadpack.py“,第388行,在_quad中返回_quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)TypeError:只有length-1数组才能转换为Python标量

from scipy.integrate import quad
import numpy as np
import matplotlib.pyplot as plt
from numpy import cos,sin,pi




lmda = 5e-7
m = 1
def Jm(thta):
    return (1/pi)*cos(m*thta-x*sin(thta))



xvals = np.linspace(-10*lmda,10*lmda,200)
zvals = np.linspace(-20*lmda,20*lmda,200)
x,z = np.meshgrid(xvals,zvals)

gb = quad(Jm,0,1e-6) [0]



plt.figure(figsize=(12,8))
plt.imshow(gb,origin='lower',extent=[-10*lmda,10*lmda,-20*lmda,20*lmda])
cbar = plt.colorbar()
cbar.ax.set_ylabel('V/m')
cbar.ax.set_xlabel('E')
plt.xlabel('x nm')
plt.ylabel('y nm')


plt.show()

回答(0)