LoginSignup
2
1

More than 5 years have passed since last update.

numpyの2次元リストから1次元リストを検索し、行番号を取得する

Last updated at Posted at 2019-04-19

numpyで2次元リストから1次元リストそのものを検索し、行番号を取得する。

import numpy as np

a=np.random.randint(0,2,(10,2))
b=np.random.randint(0,2,2)
c=np.where(np.all(a==b,axis=1))
print('a={}'.format(a))
print('b={}'.format(b))
print('c={}'.format(c[0]))

こんな感じで出力される。

a=[[0 1]
 [0 1]
 [0 1]
 [1 1]
 [0 0]
 [1 1]
 [0 0]
 [0 0]
 [0 0]
 [1 0]]
b=[1 0]
c=[9]

2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1