-
Overloads
| Name | Description |
|---|---|
(const Object lhs - const ComplexTensor rhs) -> ComplexTensor | Element-wise subtraction of Complex tensors or tensor-scalar subtraction. |
(const Object lhs - const RealTensor rhs) -> RealTensor | Element-wise subtraction of Real tensors or tensor-scalar subtraction. |
(const Object lhs - const ComplexTensor rhs) -> ComplexTensor
Element-wise subtraction of Complex tensors or tensor-scalar subtraction.
Subtracts one tensor from another element-wise, or subtracts a scalar from a tensor, or subtracts a tensor from a scalar.
For tensor-tensor subtraction:
- Both tensors must have the same shape.
- Result[i,j,k,...] = A[i,j,k,...] - B[i,j,k,...]
For tensor-scalar subtraction:
- The scalar is substracted from every element of the tensor.
- Result[i,j,k,...] = A[i,j,k,...] - s
For scalar-tensor subtraction:
- The output tensor is the scalar minus each element of the tensor.
- Result[i,j,k,...] = s - B[i,j,k,...].
Parameters
- rhs: Second operand: complex tensor or scalar.
Returns
A new complex tensor containing the element-wise difference.
Example
// Subtract two tensors
var A = filled_tensor([2, 3], 5.0, as_complex)
var B = filled_tensor([2, 3], 2.0, as_complex)
var C = A - B // Each element is 5.0 - 2.0 = 3.0
print(C[0, 0]) // 3.0
// Subtract scalar from tensor
var D = filled_tensor([2, 2], 10.0, as_complex)
var E = D - 3.0 // Each element is 10.0 - 3.0 = 7.0
print(E[1, 1]) // 7.0
// Subtract tensor from scalar
var F = filled_tensor([2, 2], 2.0, as_complex)
var G = 10.0 - F // Each element is 10.0 - 2.0 = 8.0
print(G[0, 1]) // 8.0
(const Object lhs - const RealTensor rhs) -> RealTensor
Element-wise subtraction of Real tensors or tensor-scalar subtraction.
Subtracts one tensor from another element-wise, or subtracts a scalar from a tensor, or subtracts a tensor from a scalar.
For tensor-tensor subtraction:
- Both tensors must have the same shape.
- Result[i,j,k,...] = A[i,j,k,...] - B[i,j,k,...]
For tensor-scalar subtraction:
- The scalar is substracted from every element of the tensor.
- Result[i,j,k,...] = A[i,j,k,...] - s
For scalar-tensor subtraction:
- The output tensor is the scalar minus each element of the tensor.
- Result[i,j,k,...] = s - B[i,j,k,...].
Parameters
- rhs: Second operand: real tensor or scalar.
Returns
A new real tensor containing the element-wise difference.
Example
// Subtract two tensors
var A = filled_tensor([2, 3], 5.0, as_real)
var B = filled_tensor([2, 3], 2.0, as_real)
var C = A - B // Each element is 5.0 - 2.0 = 3.0
print(C[0, 0]) // 3.0
// Subtract scalar from tensor
var D = filled_tensor([2, 2], 10.0, as_real)
var E = D - 3.0 // Each element is 10.0 - 3.0 = 7.0
print(E[1, 1]) // 7.0
// Subtract tensor from scalar
var F = filled_tensor([2, 2], 2.0, as_real)
var G = 10.0 - F // Each element is 10.0 - 2.0 = 8.0
print(G[0, 1]) // 8.0