1. 函数原型
argwhere(array):找到非空数组array在满足某些条件下的索引,返回索引数组。
2. 应用
2.1 一维数组
返回一个一维数组,代表当前满足条件的元素出现的位置。
# -*- coding: utf-8 -*-
import numpy as np
arr = np.random.randint(0,10, (5,))
index = np.argwhere(arr < 5)
2. 2 二维数组
返回二维数组,代表当前满足条件的元素出现的位置。
# -*- coding: utf-8 -*-
import numpy as np
"""
arr =
9 3 7 0
3 4 2 4
3 6 4 4
index =
0 1
0 3
1 0
1 1
1 2
1 3
2 0
2 2
2 3
"""
arr = np.random.randint(0,10, (3,4))
index = np.argwhere(arr < 5)
参考文献
http://blog.csdn.net/vernice/article/details/50990919