[英]Setting an array element with a sequence.The requested array has an inhomogeneous shape after1dimensions.The detected shapewas(18,)+inhomogeneouspart
I'm trying to do a scatterplot between this 2 variables, but it gives me this error.我试图在这 2 个变量之间绘制散点图,但它给了我这个错误。
ValueError: setting an array element with a sequence. ValueError:设置带有序列的数组元素。 The requested array has an inhomogeneous shape after 1 dimensions.请求的数组在 1 维后具有不均匀的形状。 The detected shape was (18,) + inhomogeneous part.检测到的形状是 (18,) + 不均匀部分。
def plot():
Age_list=[]
Lactate_list=[]
for l in range(1,19):
Age = test[test.ID == l]['age']
Lactate = (test[test.ID == l]['VO2'].nlargest(n=5).mean())*(80/100)
Lactate_list.append(Lactate)
Age_list.append(Age)
plt.scatter(Age_list, Lactate_list,color='purple')
a, b = np.polyfit(Age_list, Lactate_list, 1)
plt.plot(Age_list, a*np.array(Age_list)+b)
plt.xlabel('Age')
plt.ylabel('Lactate threshold')
plt.title('Correlation between Age and Lactate threshold')
plt.show()
If i print then length of Age_list and Lactate_list it gives the same length.如果我打印 Age_list 和 Lactate_list 的长度,它给出相同的长度。 I don't understand what is the problem.我不明白这是什么问题。 The lactate is 80% of what is inside the parenthesis.乳酸是括号内的 80%。 Is it ok how I did it?我是怎么做到的好吗?
The error is being thrown because the elements of the Age_list and Lactate_list are not arrays with the same shape.抛出错误是因为 Age_list 和 Lactate_list 的元素不是具有相同形状的 arrays。 The elements of the Age_list are series, while the elements of the Lactate_list are scalars. Age_list 的元素是系列,而 Lactate_list 的元素是标量。
try this instead试试这个
def plot():
age_list = []
lactate_list = []
for l in range(1, 19):
age = test[test.ID == l]['age'].values[0]
lactate = (test[test.ID == l]['VO2'].nlargest(n=5).mean())*(80/100)
lactate_list.append(lactate)
age_list.append(age)
plt.scatter(age_list, lactate_list, color='purple')
a, b = np.polyfit(age_list, lactate_list, 1)
plt.plot(age_list, a*np.array(age_list) + b)
plt.xlabel('Age')
plt.ylabel('Lactate Threshold')
plt.title('Correlation between Age and Lactate Threshold')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.