Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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:can';t将序列乘以类型为'的非整数;numpy.float64'&书信电报;图形尺寸432x288,带0个轴>;(不知道该怎么办)_Python_Numpy_Scipy - Fatal编程技术网

Python 错误:TypeError:can';t将序列乘以类型为'的非整数;numpy.float64'&书信电报;图形尺寸432x288,带0个轴>;(不知道该怎么办)

Python 错误:TypeError:can';t将序列乘以类型为'的非整数;numpy.float64'&书信电报;图形尺寸432x288,带0个轴>;(不知道该怎么办),python,numpy,scipy,Python,Numpy,Scipy,我想画一个包含定积分的方程。它是一个与二维量子环中的子带间跃迁有关的光离子化截面。我用解析法做了角度部分,我试图用数值方法计算径向部分 下面是我在Python代码中实现这一点的尝试: from scipy.integrate import quad import numpy as np from scipy.special import gamma from scipy.constants import alpha import matplotlib.pyplot as plt #Consta

我想画一个包含定积分的方程。它是一个与二维量子环中的子带间跃迁有关的光离子化截面。我用解析法做了角度部分,我试图用数值方法计算径向部分

下面是我在Python代码中实现这一点的尝试:

from scipy.integrate import quad
import numpy as np
from scipy.special import gamma
from scipy.constants import alpha
import matplotlib.pyplot as plt

#Constants
epsilon = 13.1 #dielectric constant of the material
gamma_C = 0.5 # donor impurity linewidth 
nr = 3.2 #refractive index of semiconductor
flux = 0  # Phi in eqn 8 magnetic flux
R = 5  #radius of the qunatum ring in nm
r = np.linspace(0, 6 * R)
rho = r / R
m_0 = 0.0067*0.511 # electron effective mass
h = 4.13e-15 # Planck constant in eV
hbar =  6.58e-16 # reduced Planck constant in eV
#Photon energy
hnu = np.linspace(0, 100) #in eV


#Function that calculates the integrand
def func(rho):
    betai = np.sqrt( gama**4/4)
    betaf = np.sqrt(1+gama**4/2)
    return ((gama * rho)**(betai + betaf) *
            np.exp(-1/2*(gama * rho)**2) 
         * (gama * rho)**2/2   ) 

def cross_section(hnu, gama):
    #function that calculates the photoionisation cross section
    betai = np.sqrt( gama**4/4)
    betaf = np.sqrt(1+gama**4/2)
    Ei = gama**2*(1+betai)-gama**4/2
    Ef = gama**2*(3+betaf)-gama**4/2
    return (nr/epsilon * 4*np.pi/3 * alpha * hnu *
            (abs(R * np.sqrt(1/2**betai*gamma(betai + 1))*
            np.sqrt(1/2**betaf*gamma(betaf + 1)) *
            quad(func, 0, np.infty))**2 * 
             hbar * gamma_C/(Ef - Ei - hnu)**2 + ( hbar * gamma_C)**2))

#Plot

plt.figure();plt.clf()

for gama in [1.0, 1.5, 2.0]:
    plt.plot(hnu, cross_section(hnu, gama))
但我一直收到这个错误

TypeError: can't multiply sequence by non-int of type 'numpy.float64'


有人知道原因以及如何避免这种情况吗?

再看一看文档字符串。特别是,请查看“返回”部分。您将看到它返回多个值。更准确地说,它返回一个值元组。实际值的数量取决于参数
满输出
,但它始终至少包括两个值,数值计算的积分和误差估计

在此代码中

    return (nr/epsilon * 4*np.pi/3 * alpha * hnu *
            (abs(R * np.sqrt(1/2**betai*gamma(betai + 1))*
            np.sqrt(1/2**betaf*gamma(betaf + 1)) *
            quad(func, 0, np.infty))**2 * 
             hbar * gamma_C/(Ef - Ei - hnu)**2 + ( hbar * gamma_C)**2))
您使用了
quad
的返回值,但这是一个元组,因此在该表达式中无法正常工作。要修复它,只需拉出
quad
返回的元组的第一个值。也就是说,将
quad(func,0,np.infty)
替换为
quad(func,0,np.infty)[0]

    return (nr/epsilon * 4*np.pi/3 * alpha * hnu *
            (abs(R * np.sqrt(1/2**betai*gamma(betai + 1))*
            np.sqrt(1/2**betaf*gamma(betaf + 1)) *
            quad(func, 0, np.infty)[0])**2 * 
             hbar * gamma_C/(Ef - Ei - hnu)**2 + ( hbar * gamma_C)**2))

跟踪堆栈跟踪,运行调试器,如果仍然卡住,则进行MCVE。无论何时报告Python错误,都要在问题中包含完整的回溯(即完整的错误消息)。其中有一些有用的信息可以帮助某人(包括您)找到问题的根源。值的顺序如docstring中所述。第一个是数值计算的积分,第二个是误差估计。