【发布时间】:2021-01-26 12:22:58
【问题描述】:
numpy.nonzero 对于获取非零元素的索引很有用。它返回一个数组元组,每个数组都包含特定轴的非零元素的索引。
除了 zero 元素之外,是否有等价的元素?
对于给定的numpy数组的意思
x = [[1, 2, 0],
[8, 0, 2],
[0, 0, 1]]
我可以得到如下索引
ax0_zero_idxs, ax1_zero_idxs = numpy.zero(x)
在哪里
ax0_zero_idxs = [0, 1, 2, 2]
ax1_zero_idxs = [2, 1, 0, 1]
【问题讨论】:
-
只用
x==0和np.nonzero?