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

前端 未结 3 2051
终归单人心
终归单人心 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:44

    Just use np.asarray function. In your case:

    >>> import numpy as np
    >>> array = np.array([1,2,3,4,5,6,7,8,9])
    >>> pippo = np.asarray(np.where(array>4))
    >>> pippo + 1
    array([[5, 6, 7, 8, 9]])
    

提交回复
热议问题