xorbits.numpy.select#

xorbits.numpy.select(condlist, choicelist, default=0)#

Return an array drawn from elements in choicelist, depending on conditions.

参数
  • condlist (list of bool ndarrays) – The list of conditions which 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.

返回

output – The output at position m is the m-th element of the array in choicelist where the m-th element of the corresponding array in condlist is True.

返回类型

ndarray

参见

where

Return elements from one of two arrays depending on condition.

take, choose, compress, diag, diagonal

实际案例

>>> x = np.arange(6)  
>>> condlist = [x<3, x>3]  
>>> choicelist = [x, x**2]  
>>> np.select(condlist, choicelist, 42)  
array([ 0,  1,  2, 42, 16, 25])
>>> condlist = [x<=4, x>3]  
>>> choicelist = [x, x**2]  
>>> np.select(condlist, choicelist, 55)  
array([ 0,  1,  2,  3,  4, 25])

警告

This method has not been implemented yet. Xorbits will try to execute it with numpy.

This docstring was copied from numpy.