从一个矩阵中提取匹配的行并对它们进行平均,然后生成一个新的矩阵

2024-04-26 07:18:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个矩阵,其中包含唯一的行。另外,我还有一个矩阵没有唯一的行。我必须从第二个矩阵中相对于第一个矩阵选择唯一的行,如果两行具有相同的名称,则必须将值计算为两行的平均值。你知道吗

第一矩阵: Click To download the first Matrix

FIRST MATRIX

第二矩阵: Click to download the second matrix

SECOND MATRIX


Tags: theto名称download矩阵matrix平均值first
1条回答
网友
1楼 · 发布于 2024-04-26 07:18:25

由于OP没有提供所用的完整脚本代码,我只能提供与矩阵(数据库、列表等)相关的一般答案

...snippet... # all import and other processing scriptcode here...

x = matrix1
y = matrix2

count1    = 0  # matrix 1
count2    = 0  # matrix 2
count_dbl = 0  # summary of encountered doubles within both matrixes

for item1 in x:
    count1 +=1
    for item2 in y:
            count2 += 1
        if item1 == item2:
            ..do whatever you need to do here...
            count_dbl+=1

        else:
            ... do something else here...
            pass

 print ('validation check on items in matrix 1: %s - 2: %s. Doubles: %s' % (count1, count2, count_dbl)

提示:item1或item2可以是处理来自xml或excel文件等的readline信息的方法

享受;p

相关问题 更多 >