Numpy入门(七):np.where()用法

    科技2024-01-09  88

    点击跳转 《Numpy入门系列目录》


    numpy.where(condition[, x, y])

    condition: 数组,布尔值

    x, y: array_like, 可选,x与y的shape要相同,当condition中的值是true时返回x对应位置的值,false是返回y的

    功能:基于条件condition,返回值来自x或者y,即找出满足条件的数组中的位置索引

    例子

    import numpy as np a = np.arange(1, 20, 2) print(a) # [ 1 3 5 7 9 11 13 15 17 19] print(np.where(a > 10)) # (array([5, 6, 7, 8, 9], dtype=int64),)
    Processed: 0.017, SQL: 8