Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.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 努力理解错误消息_Python - Fatal编程技术网

Python 努力理解错误消息

Python 努力理解错误消息,python,Python,我正在尝试运行下面的代码,其中列出了Bwavelength、吞吐量和newflux def ABconversion(Bwavelength, throughput): ABconstant=[] c=3e18 i=0 for i in range(0, len(Bwavelength)): ABconstant.append(((3e18/((Bwavelength[i])**2))*throughput[i])) i+=1

我正在尝试运行下面的代码,其中列出了Bwavelength、吞吐量和newflux

def ABconversion(Bwavelength, throughput):
    ABconstant=[]

    c=3e18
    i=0
    for i in range(0, len(Bwavelength)):
        ABconstant.append(((3e18/((Bwavelength[i])**2))*throughput[i]))
        i+=1
        print len(Bwavelength), len(ABconstant), ABconstant
        a=Bwavelength[0]
        b=Bwavelength[-1]
        h=((b-a)/len(Bwavelength))
        ABflux = numpy.trapz(Bwavelength, ABconstant, h)
        return ABflux

 def ABmagnitude(newflux, ABflux):
    ABmagarray=[]
    for i in range(len(newflux)):
        ABmag = -2.5*log10((newflux[i])/ABflux) - 48.6
        ABmagarray.append(ABmag)
    return ABmagarray

ABflux1 = ABconversion(Bwavelength, throughput)
print ABflux1
ABmagarray = ABmagnitude(z, ABflux1)
print epoch, ABmagarray
z在文件的前面定义,也是一个列表

但是,当我运行此命令时,会收到以下消息:

Traceback (most recent call last):
  File "Rewrite17.11.2014.py", line 196, in <module>
    ABflux1 = ABconversion(Bwavelength, throughput)
  File "Rewrite17.11.2014.py", line 186, in ABconversion
    ABflux = numpy.trapz(Bwavelength, ABconstant, h)
  File "C:\Python27\lib\site-packages\numpy\lib\function_base.py, line 3234, in trapz
    ret = add.reduce(d * (y[slice1]+y[slice2]/2.0, axis)
ValueError: Operands could not be broadcast together with shapes (0,) (444,)
回溯(最近一次呼叫最后一次):
文件“Rewrite17.11.2014.py”,第196行,在
ABflux1=ABconversion(Bwavelength,吞吐量)
文件“Rewrite17.11.2014.py”,第186行,在ABconversion中
ABflux=numpy.trapz(Bwavelength,ABconstant,h)
文件“C:\Python27\lib\site packages\numpy\lib\function\u base.py,第3234行,在trapz中
ret=增加.减少(d*(y[slice1]+y[slice2]/2.0,轴)
ValueError:操作数无法与形状(0,)(444,)一起广播
我不太理解这个错误(我对编程相当陌生),但我认为这意味着这两个“形状”没有相同的尺寸。我不确定这是为什么

提前感谢。

根据
trapz(y,x,dx,axis)
的参数:

  • y
    -类似于数组的-要集成的输入数组
  • x
    -可选数组-如果
    x
    为无,则所有
    y
    元素之间的间距为
    dx
  • dx
    -可选标量-如果
    x
    为无,则假定
    dx
    给出的间距。默认值为1
  • -可选整数-指定轴
因此,您不应该同时指定
x
dx
——其中一个应该是
None

也许这就是您想要的:
trapz(Bwavelength,None,h)

有关错误消息和NumPy的“braodcasting规则”的更多详细信息,请参阅。替换:

numpy.trapz(Bwavelength, ABconstant, h)
与:


打印len(Bwavelength)、len(ABconstant)、ABconstant什么?它打印445,1[0.0]
numpy.trapz(np.array(Bwavelength)[:,np.newaxis], ABconstant, h)