Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 ValueError:操作数无法与形状(7,)(6,)(7,)一起广播_Python_Arrays_Numpy_Vector - Fatal编程技术网

Python ValueError:操作数无法与形状(7,)(6,)(7,)一起广播

Python ValueError:操作数无法与形状(7,)(6,)(7,)一起广播,python,arrays,numpy,vector,Python,Arrays,Numpy,Vector,我收到一条错误消息,试图在Python中运行一个脚本来重复金箔的辐照冷却时间。这就是错误: Traceback (most recent call last): File "C:/Users/wolfk/PycharmProjects/Reactor Phys In-House/iterations.py", line 26, in <module> cr_tot /= math.e ** (-2.98256E-6 * out_times[l]) ValueError:

我收到一条错误消息,试图在Python中运行一个脚本来重复金箔的辐照冷却时间。这就是错误:

Traceback (most recent call last):
  File "C:/Users/wolfk/PycharmProjects/Reactor Phys In-House/iterations.py", line 26, in <module>
    cr_tot /= math.e ** (-2.98256E-6 * out_times[l])
ValueError: operands could not be broadcast together with shapes (7,) (6,) (7,) 
回溯(最近一次呼叫最后一次):
文件“C:/Users/wolfk/PycharmProjects/Reactor Phys In House/iterations.py”,第26行,In
cr_tot/=math.e**(-2.98256E-6*out_次[l])
ValueError:操作数无法与形状(7,)(6,)(7,)一起广播
代码非常混乱,因为我在大多数情况下使用了数值而不是变量,但是数学并不重要,我可以稍后验证。我要做的就是让这东西运转起来!所以你知道,输入和输出时间的向量是不同长度的,我试着让它们的长度相同,所以这不是问题所在。代码如下:

import numpy as np
import math
import matplotlib.pyplot as plt

in_times = np.array([[697800, 603840, 74460, 161520, 428880, 75960, 62760]])
out_times = np.array([[248880, 3960, 9240, 5400, 5880, 8760]])

cr_tot = 0
cr_fast = 0
i = 1
j = 1
k = 0
l = 0

while i < 13:
    if j == 1:
        cr_tot /= math.e ** (-2.98256E-6 * in_times[k])
        cr_fast /= math.e ** (-2.98256E-6 * in_times[k])

        cr_tot += ((2.98256E-6 * 4950377) / 0.021554) / (1 - math.e ** (-2.98256E-6 * in_times[k]))
        cr_fast += ((2.98256E-6 * 2141114) / 0.043109) / (1 - math.e ** (-2.98256E-6 * in_times[k]))

        j -= 1
        k += 1
    else:
        cr_tot /= math.e ** (-2.98256E-6 * out_times[l])
        cr_fast /= math.e ** (-2.98256E-6 * out_times[l])

        j += 1
        l += 1

    i += 1

xi_tot = (2.98256E-6 * 4950377) / (0.021554 * cr_tot)
xi_fast = (2.98256E-6 * 2141114) / (0.043109 * cr_fast)

cr_tot *= (2.98256E-6 * 4950377) / (0.021554 * xi_tot * math.e ** (-2.98256E-6 * 660) * (1 - math.e ** (-2.98256E-6 * 1000)))
cr_fast *= (2.98256E-6 * 2141114) / (0.043109 * xi_fast * math.e ** (-2.98256E-6 * 660) * (1 - math.e ** (-2.98256E-6 * 2000)))

print(cr_tot)
print(cr_fast)
将numpy导入为np
输入数学
将matplotlib.pyplot作为plt导入
in_times=np.数组([[69780060384074460161520428807596062760]]
out_times=np.array([[248888039609240540058808760]]
cr_tot=0
cr_fast=0
i=1
j=1
k=0
l=0
而我<13:
如果j==1:
cr_tot/=math.e**(-2.98256E-6*in_乘以[k])
cr_fast/=math.e**(-2.98256E-6*in_乘以[k])
cr_tot+=((2.98256E-6*4950377)/0.021554)/(1-数学e**(-2.98256E-6*in_乘以[k]))
cr_fast+=((2.98256E-6*2141114)/0.043109)/(1-数学e**(-2.98256E-6*in_乘以[k]))
j-=1
k+=1
其他:
cr_tot/=math.e**(-2.98256E-6*out_次[l])
cr_fast/=math.e**(-2.98256E-6*out_次[l])
j+=1
l+=1
i+=1
xi_tot=(2.98256E-6*4950377)/(0.021554*cr_tot)
xi_fast=(2.98256E-6*2141114)/(0.043109*cr_fast)
cr_tot*=(2.98256E-6*4950377)/(0.021554*xi_tot*math.e**(-2.98256E-6*660)*(1-math.e**(-2.98256E-6*1000)))
cr_fast*=(2.98256E-6*2141114)/(0.043109*xi_fast*math.e**(-2.98256E-6*660)*(1-math.e**(-2.98256E-6*2000)))
打印(cr_tot)
打印(cr\U fast)

如果能得到任何帮助,我将不胜感激。:)

从初始numpy数组中删除双括号实际上会有所帮助

。。。
in_times=np.数组([69780060384074460161520428807596062760])
out_times=np.数组([24888039609240540058808760])
...
输出:

0.476018036910266
0.9882585377315589
0.9728174262826453
0.9840231812760558
0.9826154332766018
0.9742111371275044
7480153046556.081
175166298775.0072

从初始numpy数组中删除双括号实际上会有所帮助

。。。
in_times=np.数组([69780060384074460161520428807596062760])
out_times=np.数组([24888039609240540058808760])
...
输出:

0.476018036910266
0.9882585377315589
0.9728174262826453
0.9840231812760558
0.9826154332766018
0.9742111371275044
7480153046556.081
175166298775.0072

我不明白你的逻辑。 在您的代码中,在开始时,if分支中的k=0和In_乘以[k]将返回数组([69780060384074460161520428880759062760])。因此,cr_tot的长度为7。然后j-=1,j=0。下一次迭代转到else分支。out_times[l]表示out_times[0],它返回长度为6的数组([248880,3960,9240,5400,5880,8760])。 但您的代码是cr_tot/=math.e**(-2.98256E-6*out_乘以[l]),使用长度为7的数组除以cr_tot(长度为6,从if分支返回)。
这就是你出错的原因。

我不理解你的逻辑。 在您的代码中,在开始时,if分支中的k=0和In_乘以[k]将返回数组([69780060384074460161520428880759062760])。因此,cr_tot的长度为7。然后j-=1,j=0。下一次迭代转到else分支。out_times[l]表示out_times[0],它返回长度为6的数组([248880,3960,9240,5400,5880,8760])。 但您的代码是cr_tot/=math.e**(-2.98256E-6*out_乘以[l]),使用长度为7的数组除以cr_tot(长度为6,从if分支返回)。 这就是你出错的原因