我想做的是:
test_dict = dict(value = 1,
property = properties_list[value-1]
)
当然,我不能这样做,因为它向我抛出一个错误,指出名称“值”未定义。
答案 0 :(得分:1)
因为您可以在定义字典后添加键,所以您可以这样做
test_dict = dict(value = 1)
test_dict['property'] = properties_list[test_dict['value']-1]
答案 1 :(得分:1)
您可以使用 Python 3.8 中引入的 assignment expression(又名“海象运算符”)来实现。
import numpy as np
correlation_strong = np.array([
[ 1.00, 0.50, 0.80, 0.75],
[ 0.50, 1.00, 0.35, 0.70],
[ 0.80, 0.35, 1.00, 0.25],
[ 0.75, 0.70, 0.25, 1.00],
])
correlation_weak = np.array([
[ 1.00, 0.10, 0.20, -0.25],
[ 0.10, 1.00, -0.35, 0.05],
[ 0.20, -0.35, 1.00, -0.40],
[ -0.25, 0.05, -0.40, 1.00],
])