简体   繁体   English

x 和 y 必须具有相同的第一维,但形状 (40,) 和 (1, 80) 错误

[英]x and y must have same first dimension, but have shapes (40,) and (1, 80) error

I'm getting an error of x and y must have same first dimensions, but have shapes (40,) and (1, 80), I've tried to look it up and was told to use numpy.array as seen below but it is still not working.我收到错误 x 和 y 必须具有相同的第一维,但具有形状 (40,) 和 (1, 80),我尝试查找它并被告知使用 numpy.array 如下所示但它仍然无法正常工作。 I understand that its due to the "- Stot" part but not sure what to do exactly我知道这是由于“- Stot”部分,但不确定该怎么做

import numpy
import matplotlib.pyplot as plt
import math
import scipy.special

kb = 1.380649*(10**-23)
Na = 20
Nb = 20
Ntot = int(Na + Nb)
qa = 0
qb = 41
Stot = 0
qaa = []
Saa = []
Sba = []
Stota = []
Snew = []
prob = 0
h = 1
pos = 0
suma = []
sumnew = []

#creates an array based on the value of qb starting from 0 to qb in increments of 1
for k in range (qa, qb-1):
    qa = qa + 1
    qb = qb - 1
    qaa += [qa]
    Sa = (qa + Na - 1) * (numpy.log(qa + Na - 1)) - (qa*numpy.log(qa)) - (Na*numpy.log(Na-1))
    Sb = (qb + Nb - 1) * (numpy.log(qb + Nb - 1)) - (qb*numpy.log(qb)) - (Nb*numpy.log(Nb-1))
    Stot = Sa + Sb + Stot
    Saa += [Sa]
    Sba += [Sb]
    
Prob = numpy.array([(Saa + Sba - Stot)])

plt.plot(qaa, Prob)
plt.title("Graph to show probability distribution of the macrostates, P(qa)")
plt.xlabel('qa')
plt.ylabel('Probability')

I can't be sure with rhis code.我不能确定 rhis 代码。 The message seems to come from the plot command, but the line having the expression "(Saa + Sba - Stot)" should trigger an error, since you Saa ans Sba are lists, and the result of their adittion is the concatenation of both lists.该消息似乎来自 plot 命令,但是具有表达式“(Saa + Sba - Stot)”的行应该会触发错误,因为您的 Saa 和 Sba 是列表,并且它们的附加结果是两个列表的串联. A list minus a float (Stot is a float) is not an allowed operation If you want to add the values of the list memberwise and then substract a value from each item, convert each list to an array before performing the substraction (an array minus a float is allowed)列表减去浮点数(Stot 是浮点数)是不允许的操作如果要按成员添加列表的值,然后从每个项目中减去一个值,请在执行减法之前将每个列表转换为数组(数组减去允许浮动)

Nevertheless, there seems to be an error in this entropy calculation.然而,这个熵计算似乎有一个错误。 What is the list Stota used for? Stota 的列表是做什么用的?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:x 和 y 必须具有相同的第一维,但具有形状 (1, 2) 和 (2,) - ValueError: x and y must have same first dimension, but have shapes (1, 2) and (2,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 - ValueError: x and y must have same first dimension, but have shapes x和y必须具有相同的第一尺寸,但形状为(30,)和(1,) - x and y must have same first dimension, but have shapes (30,) and (1,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 (6,) 和 (8,) - ValueError: x and y must have same first dimension, but have shapes (6,) and (8,) Matplotlib 错误“x 和 y 必须具有相同的第一维,但具有形状 (1,) 和 (6,)” - Matplotlib error "x and y must have same first dimension, but have shapes (1,) and (6,)" Python错误:x和y必须具有相同的一维,但形状为(8,)和(1,) - Python Error: x and y must have same first dimension, but have shapes (8,) and (1,) Matplotlib 错误:x 和 y 必须具有相同的第一维,但具有形状 (100,) 和 (449,) - Matplotlib Error: x and y must have same first dimension, but have shapes (100,) and (449,) 我收到此错误:“fx 和 y 必须具有相同的第一维但具有 python 形状” - I got this error: "f x and y must have same first dimension but have shapes python" 错误消息:x和y必须具有相同的第一尺寸,但形状为(23,)和(1,) - Error message : x and y must have same first dimension, but have shapes (23,) and (1,) 线性回归模型形状 - ValueError:x 和 y 必须具有相同的第一维,但具有形状 (5,) 和 (1, 5) - Linear regression model shapes - ValueError: x and y must have same first dimension, but have shapes (5,) and (1, 5)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM