您的位置:首页 > 编程语言 > Python开发

numpy.where() 函数翻译

2018-03-19 16:30 288 查看
函数原型:
    numpy.where(condition[,x,y])     参数: 1. condition,判定条件,布尔数组或者布尔变量
               2. x和y, 数组,非必须参数
    返回值: 1. 函数参数中有数组x和数组y,当判定条件为真时,返回的数组从x中取值,否则从数组y中取值
                   2. 函数参数中只有判定条件,返回值为满足判定条件的元组的索引。
实例:    
>>> np.where([[True, False], [True, True]],
...          [[1, 2], [3, 4]],
...          [[9, 8], [7, 6]])
array([[1, 8],
[3, 4]])
>>>
    1. 函数参数列表中有判定条件,数组x和y   
    2. 判定条件为布尔数组:[[True, False], [True, True]],x为数组[[1, 2], [3, 4]], y为数组[[9,8], [7,6]] 。
    3. 当为True时,取x中的值,为False时,取y中的值,返回的数组[[1, 8],[3, 4]]。
>>> x = np.arange(9.0).reshape(3, 3)
>>> x
array([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]])
>>> np.where(x>5)
(array([2, 2, 2], dtype=int64), array([0, 1, 2], dtype=int64))
>>>

    1. 函数参数列表中只有判定条件
    2. 判定条件为 x>5,返回满足判定条件元组的索引: [2,0], [2, 1], [2, 2],指向的元素分别为[6,7,8]
源自:http://https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: