📜  numpy.select()函数| Python

📅  最后修改于: 2022-05-13 01:55:17.991000             🧑  作者: Mango

numpy.select()函数| Python

numpy.select()()函数根据条件返回从选择列表中的元素绘制的数组。

代码#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]