- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的代码:
name = ["AAAAA 4 2 1 2 4 2 4 4 5 2 2 1 5 2 4 3 1 1 3 3 5",
"BBB 5 2 1 2 4 5 4 4 1 2 2 2 4 4 4 3 1 2 3 3 2",
"K 4 1 2 1 2 1 2 5 1 1 1 1 4 2 2 1 5 1 3 4 1"]
count = 0
for line in name:
for char in line:
if char.isdigit():
count += 1
final_count = int(count/len(name)) # 21
# count --->63
# print(len(name))--> 3 which gives the below number,
# print(final_count)--> 21
name = [name[i].split(" ") for i in range(len(name))]
for i in range(1, len(name[0])):
bb = (int(name[0][i])+int(name[1][i])+int(name[2][i]))/len(name)
for i in range(1, final_count+1):
print(i,bb)
输出:错误!
1 2.6666666666666665
2 2.6666666666666665
3 2.6666666666666665
4 2.6666666666666665
5 2.6666666666666665
6 2.6666666666666665
7 2.6666666666666665
8 2.6666666666666665
9 2.6666666666666665
10 2.6666666666666665
11 2.6666666666666665
12 2.6666666666666665
13 2.6666666666666665
14 2.6666666666666665
15 2.6666666666666665
16 2.6666666666666665
17 2.6666666666666665
18 2.6666666666666665
19 2.6666666666666665
20 2.6666666666666665
21 2.6666666666666665
右侧的正确值:
# After changing the line bb = (int(name[0][i])+int(name[1][i])+int(name[2][i]))/len(name)
to
print((int(name[0][i])+int(name[1][i])+int(name[2][i]))/len(name))
4.333333333333333
1.6666666666666667
1.3333333333333333
1.6666666666666667
3.3333333333333335
2.6666666666666665
3.3333333333333335
4.333333333333333
2.3333333333333335
1.6666666666666667
1.6666666666666667
1.3333333333333333
4.333333333333333
2.6666666666666665
3.3333333333333335
2.3333333333333335
2.3333333333333335
1.3333333333333333
3.0
3.3333333333333335
2.6666666666666665
最佳答案
您可以使用 statistics.mean
求出数字的平均值。因为你知道每一行都有相同数量的整数,所以使用 zip
同时遍历行中的每个数字:
from statistics import mean
name = ["AAAAA 4 2 1 2 4 2 4 4 5 2 2 1 5 2 4 3 1 1 3 3 5",
"BBB 5 2 1 2 4 5 4 4 1 2 2 2 4 4 4 3 1 2 3 3 2",
"K 4 1 2 1 2 1 2 5 1 1 1 1 4 2 2 1 5 1 3 4 1"]
averages = []
for i, nums in enumerate(zip(*map(str.split, name))):
if nums[0].isdigit():
avg = mean(map(int, nums))
print(f'{i} {avg:0.2f}')
averages.append(avg)
highest = ' '.join(str(i) for i, a in enumerate(averages, 1) if a == max(averages))
print(f"the highest average(s) is: #{highest} at {max(averages):0.2f}")
这个输出:
1 4.33
2 1.67
3 1.33
4 1.67
5 3.33
6 2.67
7 3.33
8 4.33
9 2.33
10 1.67
11 1.67
12 1.33
13 4.33
14 2.67
15 3.33
16 2.33
17 2.33
18 1.33
19 3.00
20 3.33
21 2.67
the highest average is: #1 8 13 at 4.33
关于python - (对于循环): How to put average values beside each number of the corresponding avg value and print the number(s) with the highest average?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59122740/
我正在努力寻找平均列的正确语法。我所拥有的——来自 RavenDB Studio 编辑器: map : from area in docs.Level5_AdministrativeAreas sel
double average = LongStream .of(-4480186093928204294L, -1340542863544260591L, -600429628624003927
我在 MySQL 表中有梦幻足球联赛的数据。我想查询一个 php 页面的数据。 我如何创建一个查询来计算球队得分与该特定年份联盟平均得分的比较? 我的(简化的)数据表如下所示: 游戏 table :
干杯,伙计们。我被要求让这段代码在学习挑战中发挥作用,但我不确定如何处理“array.average()”部分,因为它不是一个函数。 我被问到的是: var array = [5,44,23,11,5
我刚刚开始学习 Java 中的数据结构和算法(从数组开始)。我有两个问题。 在我看来,算法执行中的“步骤”是实际上是算法访问的数组的位置。因为他们说数组中的插入一步发生,因为数据项被简单地插入到第一个
嗨,我正在使用谷歌分析 api gapi查找网站的“平均 session 持续时间”和“每次访问浏览的平均页面” 我为此创建了一个仪表板,其值为 00:02:30和 4.58分别 ... 我使用以下代
SELECT username, (SUM(rating)/count(*)) as TheAverage, count(*) as TheCount FROM ratings WHERE month
在 Office Excel AVERAGE 函数示例中,参数始终使用逗号作为分隔符。但是,AVERAGE(A2:C2 B1:B10) 在 Excel 中也有效。 我的问题:有什么区别以及为什么?谢谢
我的代码: name = ["AAAAA 4 2 1 2 4 2 4 4 5 2 2 1 5 2 4 3 1 1 3 3 5", "BBB 5 2 1 2 4 5 4 4 1 2 2 2 4 4
我一直在探索适用于 Android 的 Firebase Analytics,发现控制台的仪表板显示用户参与事件,该事件显示平均屏幕时间,如“hh:mm:ss”,还通过获取以下总和来显示“值”参数的平
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我使用维基百科文章中定义的折叠更改: http://en.wikipedia.org/wiki/Fold_change 我现在处理倍数变化已经有一段时间了,但从来没有真正需要计算我所有倍数变化的平均倍
这仅与编程相关 - 与颜色及其表示有更多关系。 我正在开发一个非常底层的应用程序。我在内存中有一个字节数组。那些是字符。它们是用抗锯齿渲染的:它们的值从 0 到 255,0 表示完全透明,255 完全
我正在尝试在用户界面中实现一个监视器,该监视器显示由海龟品种(海龟自己)共享的变量的平均值。有谁知道收集所有值的方法,将它们加在一起并除以海龟的数量以获得值或知道更简单的方法? 最佳答案 如果每只海龟
我试图在我的 OpenGL 程序中将骨架动画从矩阵切换到四元数,但我遇到了一个问题: 给定多个单位四元数,我需要得到一个四元数,当用于变换向量时,将给出一个向量,该向量是每个四元数单独变换的向量的平均
输入: Clickhouse 表A business_dttm(日期时间) 金额( float ) 我需要在每个 business_dttm 上计算 15 分钟(或最后 3 条记录)的移动总和 例如
我正在尝试找到一种方法来计算移动累积平均值,而不存储迄今为止收到的计数和总数据。 我想出了两种算法,但都需要存储计数: 新平均值 = ((旧计数 * 旧数据) + 下一个数据)/下一个计数 新平均值
在我的 SQL 脚本中,我想标准化来自这样的子查询的值 select y/avg(y) from ( select x*z as y from test_table )T 我知道这个解决方案会起
由于 Controller 损坏,文件在从 USB 闪存驱动器下载时会随机损坏。我下载了同一个文件的多个副本,每个副本的错误似乎通常是唯一且随机的。 因此,我需要一个脚本来比较同一文件的几个(3 到
我正在尝试解决一个非常简单的算法分析(显然对我来说不是那么简单)。 算法是这样的: int findIndexOfN(int A[], int n) { // this algorithm looks
我是一名优秀的程序员,十分优秀!