nlcpy.select

nlcpy.select(condlist, choicelist, default=0)[ソース]

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

Parameters
condlistlist 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.

choicelistlist of ndarrays

The list of arrays from which the output elements are taken. It has to be of the same length as condlist.

defaultscalar, optional

The element inserted in output when all conditions evaluate to False.

Returns
outputndarray

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.

参考

where

Returns elements chosen from x or y depending on condition.

take

Takes elements from an array along an axis.

diag

Extracts a diagonal or construct a diagonal array.

diagonal

Returns specified diagonals.

Examples

>>> import nlcpy as vp
>>> x = vp.arange(10)
>>> condlist = [x<3, x>5]
>>> choicelist = [x, x**2]
>>> vp.select(condlist, choicelist)
array([ 0,  1,  2,  0,  0,  0, 36, 49, 64, 81])