繁体   English   中英

在numpy中的3D数组中查找2D数组的索引

[英]Find index of 2d array in a 3d array in numpy

我想在3d数组中找到2d数组。 为了在2d数组中找到1d数组,我可以使用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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM