简体   繁体   English

设置一个带有序列的数组元素。请求的数组在1维后形状不均匀。检测到的形状为(18,)+inhomogeneouspart

[英]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.

相关问题 设置具有序列的数组元素请求的数组在 1 维后具有不均匀的形状检测到的形状是 (2,)+ 不均匀的部分 - setting an array element with a sequence requested array has an inhomogeneous shape after 1 dimensions The detected shape was (2,)+inhomogeneous part Solve_ivp 设置具有序列的数组元素。请求的数组在 1 维之后具有不均匀的形状。检测到的形状为 (4,)+不均匀 - Solve_ivp setting an array element with a sequence.The requested array has a inhomogen shape after1dimensions.Thedetected shape was(4,)+inhomogeneous 请求的数组在 1 维后具有不均匀的形状。 检测到的形状为 (33,) + 不均匀部分 - The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (33,) + inhomogeneous part 设置一个带有序列的数组元素,它说我的列表是不均匀的,但我不认为它是 - setting an array element with a sequence, it says my list is inhomogeneous but i dont think it is 用序列设置数组元素 - setting an array element with a sequence 使用 odeint 时数组的形状不均匀 - Inhomogeneous shape of an array when using odeint numpy 阵列非均匀形状 2d - numpy array inhomogeneous shape 2d ValueError:使用sequence()设置数组元素 - ValueError: setting an array element with a sequence() ValueError:使用序列设置数组元素 - ValueError: setting an array element with a sequence 使用序列python设置数组元素 - Setting an array element with a sequence python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM