output of numpy.where(condition) is not an array, but a tuple of arrays: why?

前端 未结 3 2054
终归单人心
终归单人心 2020-12-23 14:08

I am experimenting with the numpy.where(condition[, x, y]) function.
From the numpy documentation, I learn that if you give just one array as input, it shou

3条回答
  •  失恋的感觉
    2020-12-23 14:45

    Short answer: np.where is designed to have consistent output regardless of the dimension of the array.

    A two-dimensional array has two indices, so the result of np.where is a length-2 tuple containing the relevant indices. This generalizes to a length-3 tuple for 3-dimensions, a length-4 tuple for 4 dimensions, or a length-N tuple for N dimensions. By this rule, it is clear that in 1 dimension, the result should be a length-1 tuple.

提交回复
热议问题