我是python的新手,我在python中遇到数组问题。所以我有一个像这样的列表的数据,我给这个列表的变量名称是fitur:
AppendData.js
然后我有条件positif和negatif的概率,索引[0]属于Node.js 9.3.0 (ia32)
索引[1]属于[['F11', '1', '0', '0'], ['F2', '1', '1', '0'], ['F4', '1', '0', '0']]
而索引[2]属于{{1} }
F11
我有公式:
F2
所以这是我的问题,我想用公式计算公式中的概率。例如
F4
等等,直到列表F11中的值完成
我希望我有这样的输出
Here is positif (bpf_pos)
[0.42857142857142855, 0.5714285714285714, 0.5714285714285714]
and here is negatif (bpf_neg)
[0.14285714285714285, 0.2857142857142857, 0.2857142857142857]
这是我的代码:
f_pd_neg = (bpf_neg[i] ** float(uji[1])) * ((1 - bpf_neg[i]) ** (1 - float(uji[1])))
f_pd_pos = (bpf_pos[i] ** float(uji[1])) * ((1 - bpf_pos[i]) ** (1 - float(uji[1])))
我尝试了bpf_neg[0] ** 1 (from the list in F11) * ((1- bpf_neg[0] ** (1 - 1)
我收到了错误Positif is:
0 [0.571428571,0.571428571,0.428571429]
1 [0.428571429,0.571428571,0.571428571]
2 [0.571428571,0.428571429,0.428571429]
Negatif is:
0 [0.285714286,0.285714286,0.714285714]
1 [0.142857143,0.857142857,0.857142857]
2 [0.285714286,0.714285714,0.714285714]
我该如何解决?我希望你能理解,因为我的英语太可怕了
答案 0 :(得分:0)
@RazBarb尝试这个,我想我理解并且结果是一样的,
lst = [['F11', '1', '0', '0'], ['F2', '1', '1', '0'], ['F4', '1', '0', '0']]
bpf_pos = [0.42857142857142855, 0.5714285714285714, 0.5714285714285714]
bpf_neg = [0.14285714285714285, 0.2857142857142857, 0.2857142857142857]
d_neg = []
d_pos = []
for i, uji in enumerate(lst):
f_pd_neg = []
f_pd_pos = []
for x in uji[1:]:
f_pd_neg.append(round((bpf_neg[i] ** float(x)) * ((1 - bpf_neg[i]) ** (1 - float(x))), 9) * 10)
f_pd_pos.append(round((bpf_pos[i] ** float(x)) * ((1 - bpf_pos[i]) ** (1 - float(x))), 9) * 10)
d_neg.append(f_pd_neg)
d_pos.append(f_pd_pos)
for i, neg in enumerate(d_neg):
print(i, neg)
for i, pos in enumerate(d_pos):
print(i, pos)
<强>输出强>
# pos
0 [0.142857143, 0.857142857, 0.857142857]
1 [0.285714286, 0.285714286, 0.714285714]
2 [0.285714286, 0.714285714, 0.714285714]
# neg
0 [0.428571429, 0.571428571, 0.571428571]
1 [0.571428571, 0.571428571, 0.428571429]
2 [0.571428571, 0.428571429, 0.428571429]
将每列乘以10后的输出
[1.4285714299999999, 8.57142857, 8.57142857]
[2.8571428599999997, 2.8571428599999997, 7.142857139999999]
[2.8571428599999997, 7.142857139999999, 7.142857139999999]
[4.28571429, 5.71428571, 5.71428571]
[5.71428571, 5.71428571, 4.28571429]
[5.71428571, 4.28571429, 4.28571429]