TypeError:“numpy.ndarray”和“list”的实例之间不支持“>”

2024-06-08 22:40:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一系列的numpy数组,看起来像这样:

mean_fall_1 = [np.nanmean(zero_to_nan(d)) for d in fall_1_gpa]
stdev_fall_1 = [np.nanstd(zero_to_nan(d)) for d in fall_1_gpa]

还有一个列表,称为组合1。 我不知道是否需要展示这些,但我也有:

def zero_to_nan(d):
    array = np.array(d)
    array[array == 0] = np.NaN
    return array

fall_1_gpa = [[mean(sub_list) for sub_list in list] for list in fall1_grades]

我想做的是找到mean和stdev的最佳组合,但同时根据两者的变化改变组合的顺序。我所做的是:

mean_fall_1, stdev_fall_1, combination_fall_1 = sorted(list(zip(*(zip(mean_fall_1, stdev_fall_1, combination_fall_1)))))
mean_fall_1, stdev_fall_1, combination_fall_1 = (list(t) for t in sorted(list(zip(*(zip(mean_fall_1, stdev_fall_1, combination_fall_1))))))

我正在尝试对它们进行分类,由于是使用zip,所以我尝试在之后解压缩它们。 我是新手,不知道无法将列表与numpy数组进行比较,因此出现以下错误: 平均值为1,标准差为1,组合为1=已排序(

TypeError: '>' not supported between instances of 'numpy.ndarray' and 'list'

有办法解决这个问题吗


Tags: toinnumpyfornpnanzipmean