numpy.select()()函数根据条件返回从选择列表中的元素绘制的数组。
用法: numpy.select(condlist, choicelist, default = 0)
参数:
condlist :[list of bool ndarrays] It determine from which array in choicelist the output elements are taken. When multiple conditions are satisfied, the first one encountered in condlist is used.
choicelist :[list of ndarrays] The list of arrays from which the output elements are taken. It has to be of the same length as condlist.
default :[scalar, optional] The element inserted in output when all conditions evaluate to False.
Return :[ndarray] An array drawn from elements in choicelist, depending on conditions.
代码1:
# Python program explaining
# numpy.select() function
# importing numpy as geek
import numpy as geek
arr = geek.arange(8)
condlist = [arr<3, arr>4]
choicelist = [arr, arr**3]
gfg = geek.select(condlist, choicelist)
print (gfg)
输出:
[ 0, 1, 2, 0, 0, 125, 216, 343]
代码2:
# Python program explaining
# numpy.select() function
# importing numpy as geek
import numpy as geek
arr = geek.arange(8)
condlist = [arr<4, arr>6]
choicelist = [arr, arr**2]
gfg = geek.select(condlist, choicelist)
print (gfg)
输出:
[ 0, 1, 2, 3, 0, 0, 0, 49]
相关用法
- Python Wand function()用法及代码示例
- Python map()用法及代码示例
- Python int()用法及代码示例
- Python dir()用法及代码示例
- Python sum()用法及代码示例
- Python id()用法及代码示例
- Python str()用法及代码示例
- Python oct()用法及代码示例
- Python now()用法及代码示例
- Python cmp()用法及代码示例
- Python ord()用法及代码示例
- Python tell()用法及代码示例
- Python hex()用法及代码示例
- Python math.tan()用法及代码示例
- Python math.gcd()用法及代码示例
- Python math.cos()用法及代码示例
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 numpy.select() function | Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。