TypeError: '>=' 在 'list' 和 'dict' 的实例之间不支持

问题描述 投票:0回答:0

我想在 python 中创建一个排列测试,我有一个观察值字典,表示为“a”,以及一个随机生成的值,表示为“b”:

  a = {0: 4,1: 3.0,2: 4.0,3: 2.0,4: 3.0,5: 3.0,6: 3.0,7: 3.0,8: 3.0,9: 3.0,10: 2.0
         ,11: 3.0,12: 2.0, 13: 4,14: 2.0,15: 3.0,16: 2.0,17: 2.0,18: 3.0}

     b=[{0: 10,1: 11,2: 10,3: 10.0,4: 10,5: 9,6: 9,7: 10,8: 10,9: 10,10: 9,11: 9.9,12: 9,13: 10,14: 10, 15: 10,  16: 10, 17: 10,18: 10}, {0: 9,1: 9,2: 9,3: 9.0,4: 10,5: 9,6: 9.0,7: 8, 8: 9,9: 10, 10: 9.4,11: 8.44,12: 9.0,13: 8.75,14: 9.4,15: 9.4,16: 8.14,17: 8.88,18: 9.85}]

我想在“a”中的观察值也是随机的假设下确定一个概率,使用:

p_value = (np.sum(b>= a) + np.sum(b <= a)) / 2

我尝试使用运算符 itemgetter:

    from operator import itemgetter
    c = sorted(b,key=itemgetter(0))
    p_value = (np.sum(c>= a) + np.sum(c <= a)) / 2

报错:

TypeError: '>=' not supported between instances of 'list' and 'dict'
,我尝试使用 for 循环:

for i in range(len(c)):
    p_value = (np.sum( c[i]>= a) + np.sum(c[i] <= a)) / 2

给出错误:

TypeError: '>=' not supported between instances of 'dict' and 'dict'

我在这里错过了什么?

python numpy dictionary scipy operators
© www.soinside.com 2019 - 2024. All rights reserved.