I want to find a 2d array in a 3d array. for finding a 1d array in a 2d array I can use np.where(np.all(a==b, axis=1))[0][0]
.
>>> import numpy as np
>>>
>>> a = np.array([[[1, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]])
>>>
>>> b = np.array([[1, 0, 0],
[0, 0, 0],
[0, 0, 0]])
>>>
>>> a.find(b)
0
axis
关键字接受元组,因此您可以简单地执行以下操作:
np.where(np.all(a==b, axis=(1, 2)))[0][0]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.