Substract two tensors element-wise. The equation is:
.. math::
out = x - y
**Note**:
``paddle.subtract`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
y (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples:
.. code-block:: python
import numpy as np
import paddle
x = paddle.to_tensor([[1, 2], [7, 8]])
y = paddle.to_tensor([[5, 6], [3, 4]])
res = paddle.subtract(x, y)
print(res)
# [[-4, -4],
# [4, 4]]
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]])
y = paddle.to_tensor([1, 0, 4])
res = paddle.subtract(x, y)
print(res)
# [[[ 0, 2, -1],
# [ 0, 2, -1]]]
x = paddle.to_tensor([2, np.nan, 5], dtype='float32')
y = paddle.to_tensor([1, 4, np.nan], dtype='float32')
res = paddle.subtract(x, y)
print(res)
# [ 1., nan, nan]
x = paddle.to_tensor([5, np.inf, -np.inf], dtype='float64')
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
Returns:
N-D Tensor. A location into which the result is stored. It's dimension equals with $x$.
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples:
Examples:
...
@@ -382,7 +444,7 @@ def remainder(x, y, name=None):
...
@@ -382,7 +444,7 @@ def remainder(x, y, name=None):
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
Returns:
N-D Tensor. A location into which the result is stored. It's dimension equals with $x$.
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples:
Examples:
...
@@ -425,7 +487,7 @@ def multiply(x, y, name=None):
...
@@ -425,7 +487,7 @@ def multiply(x, y, name=None):
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
Returns:
N-D Tensor. A location into which the result is stored. Its dimension equals with $x$.
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples:
Examples:
...
@@ -463,84 +525,118 @@ def multiply(x, y, name=None):
...
@@ -463,84 +525,118 @@ def multiply(x, y, name=None):
Compare two tensors and returns a new tensor containing the element-wise maxima. The equation is:
.. math::
out = max(x, y)
**Note**:
``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
y (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples:
.. code-block:: python
.. code-block:: python
import paddle
import numpy as np
import numpy as np
import paddle
x = paddle.to_tensor([[1, 2], [3, 4]])
x = paddle.to_tensor([[1, 2], [7, 8]])
y = paddle.to_tensor([[5, 6], [7, 8]])
y = paddle.to_tensor([[3, 4], [5, 6]])
res = paddle.maximum(x, y)
res = paddle.maximum(x, y)
print(res)
print(res)
#[[5. 6.]
# [[3, 4],
# [7. 8.]]
# [7, 8]]
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]])
x = paddle.to_tensor([[1, 2, 3], [1, 2, 3]])
y = paddle.to_tensor([1, 2])
y = paddle.to_tensor([3, 0, 4])
res = paddle.maximum(x, y, axis=1)
res = paddle.maximum(x, y)
print(res)
print(res)
#[[[1. 2. 3.]
# [[3, 2, 4],
# [2. 2. 3.]]]
# [3, 2, 4]]
x = paddle.to_tensor([2, 3, 5], dtype='float32')
x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, 4, np.nan], dtype='float32')
y = paddle.to_tensor([1, np.nan, np.nan], dtype='float32')
res = paddle.maximum(x, y)
res = paddle.maximum(x, y)
print(res)
print(res)
#[ 2. 4. nan]
# [ 2., nan, nan]
x = paddle.to_tensor([5, 3, np.inf], dtype='float32')
x = paddle.to_tensor([5, 3, np.inf], dtype='float32')
y = paddle.to_tensor([1, 4, 5], dtype='float32')
y = paddle.to_tensor([1, -np.inf, 5], dtype='float32')
Compare two tensors and returns a new tensor containing the element-wise minima. The equation is:
.. math::
out = min(x, y)
**Note**:
``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
y (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples:
.. code-block:: python
.. code-block:: python
import paddle
import numpy as np
import numpy as np
import paddle
x = paddle.to_tensor([[1, 2], [3, 4]], dtype='float32')
x = paddle.to_tensor([[1, 2], [7, 8]])
y = paddle.to_tensor([[5, 6], [7, 8]], dtype='float32')
y = paddle.to_tensor([[3, 4], [5, 6]])
res = paddle.minimum(x, y)
res = paddle.minimum(x, y)
print(res)
print(res)
#[[1. 2.]
# [[1, 2],
# [3. 4.]]
# [5, 6]]
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]], dtype='float32')
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]])
y = paddle.to_tensor([1, 2], dtype='float32')
y = paddle.to_tensor([3, 0, 4])
res = paddle.minimum(x, y, axis=1)
res = paddle.minimum(x, y)
print(res)
print(res)
#[[[1. 1. 1.]
# [[[1, 0, 3],
# [2. 2. 2.]]]
# [1, 0, 3]]]
x = paddle.to_tensor([2, 3, 5], dtype='float32')
x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, 4, np.nan], dtype='float32')
y = paddle.to_tensor([1, np.nan, np.nan], dtype='float32')
res = paddle.minimum(x, y)
res = paddle.minimum(x, y)
print(res)
print(res)
#[ 1. 3. nan]
# [ 1., nan, nan]
x = paddle.to_tensor([5, 3, np.inf], dtype='float32')
x = paddle.to_tensor([5, 3, np.inf], dtype='float64')
y = paddle.to_tensor([1, 4, 5], dtype='float32')
y = paddle.to_tensor([1, -np.inf, 5], dtype='float64')