Subtracts two arrays element-wise. You can also use the - operator.
Arguments
- lhs, rhs
(
arrayish)
Two inputs with a common data type. Can be any numeric data type. Scalars are broadcast. An R value takes the other operand's data type when that is in its own or a higher category. Otherwise it settles on its default data type, and the operands meet at their common data type.- e1, e2
(
arrayish)
The operands of the operator, which it passes on aslhsandrhs.
Value
(arrayish)
Has the inputs' broadcast shape and common data type.
See also
prim_sub() for the underlying primitive.
Examples
x <- nv_array(c(4, 5, 6))
y <- nv_array(c(1, 2, 3))
nv_sub(x, y)
#> AnvlArray
#> 3
#> 3
#> 3
#> [ CPUf32{3} ]
x - y
#> AnvlArray
#> 3
#> 3
#> 3
#> [ CPUf32{3} ]
# different data types are promoted to their common one
nv_sub(nv_scalar(5, "f32"), nv_scalar(3, "f64"))
#> AnvlArray
#> 2
#> [ CPUf64{} ]
# a scalar is broadcast and an R integer is converted to a float
x - 1L
#> AnvlArray
#> 3
#> 4
#> 5
#> [ CPUf32{3} ]