为了账号安全,请及时绑定邮箱和手机立即绑定

Python 二维数组查询元素所在子数组索引

/ 猿问

Python 二维数组查询元素所在子数组索引

List也好,np.ndarray也可以,有没有方法做下面的运算呢
下面是一个想法,不知道py是否有比较效率的方法(可以避开for,while循环的那种)
Input:a=4
          arr=[[1,2,3],[5,6],[4,7,8]]
          If a in arr
Output: True 2
能返回[False,False,True]也可以

查看完整描述

2 回答

?
慕雪4097207

https://dribbble.com/shots/8532408

https://dribbble.com/shots/8532495

https://dribbble.com/shots/8532572

https://dribbble.com/shots/8532607

https://dribbble.com/shots/8575043

https://dribbble.com/shots/8575056

https://dribbble.com/shots/8575070

https://dribbble.com/shots/8575084

https://dribbble.com/shots/8575099

https://dribbble.com/shots/8935601

https://dribbble.com/shots/8935613

https://dribbble.com/shots/8935627

https://dribbble.com/shots/8935635

https://dribbble.com/shots/8935648

https://dribbble.com/shots/8950872

https://dribbble.com/shots/8950995

https://dribbble.com/shots/8951075

https://dribbble.com/shots/8951164

https://dribbble.com/shots/8951223

https://dribbble.com/shots/9156658

https://dribbble.com/shots/9156690

https://dribbble.com/shots/9156719

https://dribbble.com/shots/9156727

https://dribbble.com/shots/9156729

https://dribbble.com/shots/9156815

https://dribbble.com/shots/9156833

https://dribbble.com/shots/9156856

https://dribbble.com/shots/9156858

https://dribbble.com/shots/9156860

https://dribbble.com/shots/9156923

https://dribbble.com/shots/9156935

https://dribbble.com/shots/9156942

https://dribbble.com/shots/9156980

https://dribbble.com/shots/9156983

https://dribbble.com/shots/9157021

https://dribbble.com/shots/9157023

https://dribbble.com/shots/9157025

https://dribbble.com/shots/9157030

https://dribbble.com/shots/9157033

https://dribbble.com/shots/9157090

https://dribbble.com/shots/9157093

https://dribbble.com/shots/9157096

https://dribbble.com/shots/9157115

https://dribbble.com/shots/9157116

https://dribbble.com/shots/9158965

https://dribbble.com/shots/9158971

https://dribbble.com/shots/9158977

https://dribbble.com/shots/9158986

https://dribbble.com/shots/9158993

https://dribbble.com/shots/9162535

https://dribbble.com/shots/9162547

https://dribbble.com/shots/9162556

https://dribbble.com/shots/9162568

https://dribbble.com/shots/9162576

https://dribbble.com/shots/9162603

https://dribbble.com/shots/9162606

https://dribbble.com/shots/9162613

https://dribbble.com/shots/9162621

https://dribbble.com/shots/9162625

https://dribbble.com/shots/9162721

https://dribbble.com/shots/9162730

https://dribbble.com/shots/9162733

https://dribbble.com/shots/9162735


查看完整回答
反对 回复 2020-01-01
?
何永灿

# 可以用Python中的map()+lambda表达式来解决:

arr = [[1,2,3], [5,6], [4,7,8]]

a = 4

r = map(lambda i:a in i, arr)

print(list(r))

—>[False, False, True]


查看完整回答
反对 回复 2018-03-22

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信