numpy.where有两种用法,
1. np.where(condition, x, y)
如果condition是一维数组,相当于[xv if c else yv for (c,xv,yv) in zip(condition,x,y)]
如果condition是高维数组,同样是把x和y做zip操作,然后根据条件的T/F进行选择
2.np.where(condition)
只有条件 (condition),则输出满足条件 (即非0) 元素的坐标 (等价于numpy.nonzero)。这里的坐标以tuple的形式给出,通常原数组有多少维,输出的tuple中就包含几个数组,每个数组的第i个位置对应符合条件元素的各维坐标。
参考链接: