【发布时间】:2022-01-12 14:00:18
【问题描述】:
我需要用我拥有的一些值构建一个矩阵,但作为一个元组,我有一个字典,其中 vales 是协调器,键只是一个 id,我需要做的是构建一个 5X6 矩阵并附加中的值 我的代码是这样的:
DIC = {1: (0.0, 0.0), 6: (0.0, 0.14), 2: (0.14, 0.0), 7: (0.14, 0.14), 3: (0.28, 0.0), 8: (0.28, 0.14), 4: (0.42, 0.0), 9: (0.42, 0.14), 5: (0.56, 0.0), 10: (0.56, 0.14), 11: (0.0, 0.28), 12: (0.14, 0.28), 13: (0.28, 0.28), 14: (0.42, 0.28), 15: (0.56, 0.28), 16: (0.0, 0.42), 17: (0.14, 0.42), 18: (0.28, 0.42), 19: (0.42, 0.42), 20: (0.56, 0.42), 21: (0.0, 0.56), 22: (0.14, 0.56), 23: (0.28, 0.56), 24: (0.42, 0.56), 25: (0.56, 0.56), 26: (0.0, 0.7), 27: (0.14, 0.7), 28: (0.28, 0.7), 29: (0.42, 0.7), 30: (0.56, 0.71)}
w, h = 5, 6
position = [[(tuple(DIC[element]) for element in DIC) for x in range(w)] for y in range(h)]
print(position)
不幸的是,我在运行代码时遇到了这个问题
at 0x7fccc7ff37b0>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3820>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3890>], [<generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3900>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3970>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff39e0>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3a50>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3ac0>], [<generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3b30>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3ba0>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3c10>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3c80>, <generator object <listcomp>.<listcomp>.<genexpr> at 0x7fccc7ff3cf0>]]
有人知道如何获取这些值吗???
【问题讨论】:
-
问题不清楚:dict中的值应该如何使用?
标签: python arrays dictionary matrix