Find indices of elements equal to zero in a NumPy array

前端 未结 8 1318
孤城傲影
孤城傲影 2020-11-29 17:28

NumPy has the efficient function/method nonzero() to identify the indices of non-zero elements in an ndarray object. What is the most efficient way to obtain th

8条回答
  •  温柔的废话
    2020-11-29 17:56

    numpy.where() is my favorite.

    >>> x = numpy.array([1,0,2,0,3,0,4,5,6,7,8])
    >>> numpy.where(x == 0)[0]
    array([1, 3, 5])
    

提交回复
热议问题