mindspore.numpy.select

mindspore.numpy.select(condlist, choicelist, default=0)[源代码]

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

参数
  • condlist (Union[int, float, bool, list, tuple, Tensor]) – 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 (Union[int, float, bool, list, tuple, Tensor]) – 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. Defaults to 0.

返回

Tensor, 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.

异常

ValueError – If len(condlist) != len(choicelist).

Supported Platforms:

Ascend GPU CPU

样例

>>> import mindspore.numpy as np
>>> condlist = [[True, True, True, False, False], [False, False, True, False, True]]
>>> choicelist = [[0, 1, 2, 3, 4], [0, 1, 4, 9, 16]]
>>> output = np.select(condlist, choicelist)
>>> print(output)
[ 0  1  2  0 16]