fn
subtract
→Tensorsubtract(a: Tensor, b: Tensor | Scalar, alpha: float = ...)Element-wise subtraction with an optional scalar multiplier.
Computes element-wise, broadcasting a
and b to a common shape and following the standard dtype-promotion
rules.
Parameters
aTensorMinuend.
bTensor | ScalarSubtrahend. Python scalars are broadcast against
a.alphafloatScalar multiplier applied to
b before subtraction.
Defaults to 1.0 (plain subtraction).Returns
TensorElement-wise difference of the broadcast shape of a and b.
Notes
Mathematical definition:
Dtype follows standard promotion: e.g. int64 - float32 → float32.
Gradients flow as and
.
Examples
>>> import lucid
>>> a = lucid.tensor([4.0, 5.0])
>>> b = lucid.tensor([1.0, 2.0])
>>> lucid.subtract(a, b, alpha=2.0)
Tensor([2., 1.])