怎么求一个向量数据在 python二维数组 中的 哪一行?

如下图所示,怎么求b在a的哪一行?有具体的函数最好图片说明

2个回答

k=(a==b).sum(1)
k=list(k)
print(k.index(len(b)))

L = [[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
[12, 13, 14, 15, 16, 17, 18, 19, 20, 21],
[13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
[14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
[15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
[16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
[17, 18, 19, 20, 21, 22, 23, 24, 25, 26],
[18, 19, 20, 21, 22, 23, 24, 25, 26, 27],
[19, 20, 21, 22, 23, 24, 25, 26, 27, 28],
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]]

a = []
for i in range(10):
    b = input()
    a.append(int(b))
print(a)
if a in L:
    print(L.index(a))


结果:
21
22
23
24
25
26
27
28
29
30
[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
11

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问