asc2.where
- asc2.where(mask: LocalTensor, src0: LocalTensor | PlainValue | int | float, src1: LocalTensor | PlainValue | int | float) LocalTensor
Select elements from two sources based on a mask.
For each element, returns the corresponding element from
src0if the mask element is true (non-zero), otherwise returns the element fromsrc1.The supported data types for
src0andsrc1:int16,int32,float16,bfloat16,float32.- Parameters:
mask – A boolean tensor specifying which elements to select
src0 – The source for elements where mask is true (tensor or scalar)
src1 – The source for elements where mask is false (tensor or scalar)
- Returns:
A tensor with elements selected from
src0orsrc1based on the mask- Return type:
- Raises:
TypeError – If mask is not a
LocalTensor, or ifsrc0orsrc1is not aLocalTensoror scalarRuntimeError – If mask dtype is not
int1, or ifsrc0orsrc1dtype is not supported
Note
At least one of
src0orsrc1must be a tensor with the same shape as the mask. Scalars are broadcast to the mask shape.Examples
Select elements from two tensors based on a mask:
mask = tensor_a > tensor_b result = asc2.where(mask, tensor_a, tensor_b)
Select elements from a tensor or a scalar based on a mask:
mask = tensor > 0 result = asc2.where(mask, tensor, 0)