回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个浮动列表,其中一些隐藏的“级别”信息以浮动的比例编码,我可以将浮动的“级别”拆分为:</p>
<pre><code>import math
import numpy as np
all_scores = [1.0369411057174144e+22, 2.7997409854370188e+23, 1.296176382146768e+23,
6.7401171871631936e+22, 6.7401171871631936e+22, 2.022035156148958e+24, 8.65845823274041e+23,
1.6435516525621017e+24, 2.307193960221247e+24, 1.285806971089594e+24, 9603539.08653573,
17489013.841076534, 11806185.6660164, 16057293.564414097, 8546268.728385007, 53788629.47091801,
31828243.07349571, 51740168.15200098, 53788629.47091801, 22334836.315934014,
4354.0, 7474.0, 4354.0, 4030.0, 6859.0, 8635.0, 7474.0, 8635.0, 9623.0, 8479.0]
easy, med, hard = [], [], []
for i in all_scores:
if i > math.exp(50):
easy.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(i)
elif i > math.exp(10):
med.append(i)
else:
hard.append(i)
print ([easy, med, hard])
</code></pre>
<p>[出来]:</p>
^{pr2}$
<p>我还有另一个与<code>all_scores</code>列表相对应的列表:</p>
<pre><code>input_scores = [0.0, 2.7997409854370188e+23, 0.0, 6.7401171871631936e+22, 0.0, 0.0, 8.6584582327404103e+23, 0.0, 2.3071939602212471e+24, 0.0, 0.0, 17489013.841076534, 11806185.6660164, 0.0, 8546268.728385007, 0.0, 31828243.073495708, 51740168.152000979, 0.0, 22334836.315934014, 4354.0, 7474.0, 4354.0, 4030.0, 0.0, 8635.0, 0.0, 0.0, 0.0, 8479.0]
</code></pre>
<p>我需要检查有多少简单的、中等的和困难的匹配所有的分数,我可以这样做来得到布尔值,在平坦的<code>all_scores</code>列表上是否有匹配:</p>
<pre><code>matches = [i == j for i, j in zip(input_scores, all_scores)]
print ([i == j for i, j in zip(input_scores, all_scores)])
</code></pre>
<p>[出来]:</p>
<pre><code>[False, True, False, True, False, False, True, False, True, False, False, True, True, False, True, False, True, True, False, True, True, True, True, True, False, True, False, False, False, True]
</code></pre>
<p><strong>有没有办法知道比赛中有多少简单/中等/困难,以及每个级别的比赛总数?</strong></p>
<p>我试过了,效果很好:</p>
<pre><code>matches = [int(i == j) for i, j in zip(input_scores, all_scores)]
print(sum(matches[:len(easy)]) , len(easy), sum(np.array(easy) * matches[:len(easy)]) )
print(sum(matches[len(easy):len(easy)+len(med)]), len(med), sum(np.array(med) * matches[len(easy):len(easy)+len(med)]) )
print (sum(matches[len(easy)+len(med):]) , len(hard), sum(np.array(hard) * matches[len(easy)+len(med):]) )
</code></pre>
<p>[出来]:</p>
<pre><code>4 10 3.52041505391e+24
6 10 143744715.777
6 10 37326.0
</code></pre>
<p>但是必须有一种不那么冗长的方法来实现相同的输出。在</p>