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:
.. code-block:: python
.. math::
out = max(x, y)
import paddle
**Note**:
import numpy as np
``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
x = paddle.to_tensor([[1, 2], [3, 4]])
Args:
y = paddle.to_tensor([[5, 6], [7, 8]])
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
res = paddle.maximum(x, y)
y (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
print(res)
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
#[[5. 6.]
# [7. 8.]]
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.
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]])
y = paddle.to_tensor([1, 2])
Examples:
res = paddle.maximum(x, y, axis=1)
print(res)
.. code-block:: python
#[[[1. 2. 3.]
# [2. 2. 3.]]]
import numpy as np
import paddle
x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, 4, np.nan], dtype='float32')
x = paddle.to_tensor([[1, 2], [7, 8]])
res = paddle.maximum(x, y)
y = paddle.to_tensor([[3, 4], [5, 6]])
print(res)
res = paddle.maximum(x, y)
#[ 2. 4. nan]
print(res)
# [[3, 4],
x = paddle.to_tensor([5, 3, np.inf], dtype='float32')
# [7, 8]]
y = paddle.to_tensor([1, 4, 5], dtype='float32')
res = paddle.maximum(x, y)
x = paddle.to_tensor([[1, 2, 3], [1, 2, 3]])
print(res)
y = paddle.to_tensor([3, 0, 4])
#[ 5. 4. inf]
res = paddle.maximum(x, y)
print(res)
# [[3, 2, 4],
# [3, 2, 4]]
x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, np.nan, np.nan], dtype='float32')
res = paddle.maximum(x, y)
print(res)
# [ 2., nan, nan]
x = paddle.to_tensor([5, 3, np.inf], 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:
.. code-block:: python
.. math::
out = min(x, y)
import paddle
**Note**:
import numpy as np
``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
x = paddle.to_tensor([[1, 2], [3, 4]], dtype='float32')
Args:
y = paddle.to_tensor([[5, 6], [7, 8]], dtype='float32')
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
res = paddle.minimum(x, y)
y (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
print(res)
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
#[[1. 2.]
# [3. 4.]]
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.
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]], dtype='float32')
y = paddle.to_tensor([1, 2], dtype='float32')
Examples:
res = paddle.minimum(x, y, axis=1)
print(res)
.. code-block:: python
#[[[1. 1. 1.]
# [2. 2. 2.]]]
import numpy as np
import paddle
x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, 4, np.nan], dtype='float32')
x = paddle.to_tensor([[1, 2], [7, 8]])
res = paddle.minimum(x, y)
y = paddle.to_tensor([[3, 4], [5, 6]])
print(res)
res = paddle.minimum(x, y)
#[ 1. 3. nan]
print(res)
# [[1, 2],
x = paddle.to_tensor([5, 3, np.inf], dtype='float32')
# [5, 6]]
y = paddle.to_tensor([1, 4, 5], dtype='float32')
res = paddle.minimum(x, y)
x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]])
print(res)
y = paddle.to_tensor([3, 0, 4])
#[1. 3. 5.]
res = paddle.minimum(x, y)
print(res)
# [[[1, 0, 3],
# [1, 0, 3]]]
x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, np.nan, np.nan], dtype='float32')
res = paddle.minimum(x, y)
print(res)
# [ 1., nan, nan]
x = paddle.to_tensor([5, 3, np.inf], dtype='float64')
y = paddle.to_tensor([1, -np.inf, 5], dtype='float64')