torch.Tensor.Tensor.less_equal
Tensor.less_equal(other: number): Tensor<S, 'bool', Dev>Tensor.less_equal<O extends Shape>(other: Tensor<O>): Tensor<DynamicShape, 'bool', Dev>Alias for le() - element-wise less-than-or-equal comparison.
Returns a boolean tensor indicating which elements are less than or equal to the comparison value. Useful for:
- Upper bound checking (at or below limit)
- Range validation
- Creating inclusive boundaries
- Conditional filtering
- Binary masking for selection
- Comparison is element-wise; broadcasting applies if shapes differ
- Result is always a boolean tensor, not 0/1
- For NaN: any comparison with NaN returns false
Parameters
othernumber- Scalar or tensor to compare with (broadcasts to match shape)
Returns
Tensor<S, 'bool', Dev>– Boolean tensor where true indicates self[i] = other[i]Examples
// Compare with scalar
const x = torch.tensor([1, 2, 3, 4]);
const result = x.less_equal(3); // [true, true, true, false]
// Compare two tensors
const a = torch.tensor([1, 5, 3]);
const b = torch.tensor([2, 4, 3]);
a.less_equal(b); // [true, false, true]
// Range validation - within bounds [min, max]
const values = torch.tensor([0.5, 1.2, 0.8, 1.5]);
const min_bound = 0.5;
const max_bound = 1.2;
const in_range = values.less_equal(max_bound).logical_and(values.greater_equal(min_bound));
// Probability values (should be ≤ 1)
const probs = torch.tensor([0.3, 0.95, 1.1, 0.5]);
const valid = probs.less_equal(1.0); // [true, true, false, true]See Also
- PyTorch torch.less_equal()
- le - Canonical name for this operation
- less - Less than (strict)
- greater_equal - Greater than or equal
- masked_select - Select elements using boolean mask