Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,7 @@ def expand(x, shape, name=None):

Expand the input tensor to a given shape.

Both the number of dimensions of ``x`` and the number of elements in ``shape`` should be less than or equal to 6. The dimension to expand must have a value 1.
Both the number of dimensions of ``x`` and the number of elements in ``shape`` should be less than or equal to 6. And the number of dimensions of ``x`` should be less than the number of elements in ``shape``. The dimension to expand must have a value 1.


Args:
Expand Down
52 changes: 45 additions & 7 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,55 @@ def _elementwise_op(helper):

def add(x, y, name=None):
"""
Examples:
Elementwise Add Operator.
Add two tensors element-wise
The equation is:

.. code-block:: python
.. math::

import paddle
Out=X+Y

X : a tensor of any dimension.
Y: a tensor whose dimensions must be less than or equal to the dimensions of X.

There are two cases for this operator:
1. The shape of Y is the same with X.
2. The shape of Y is a continuous subsequence of X.
For case 2:
1. Broadcast Y to match the shape of X, where axis is the start dimension index for broadcasting Y onto X.
2. If axis is -1 (default), axis=rank(X)−rank(Y).
3. The trailing dimensions of size 1 for Y will be ignored for the consideration of subsequence, such as shape(Y) = (2, 1) => (2).

For example:

.. code-block:: python

shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0

x = paddle.to_tensor([2, 3, 4], 'float64')
y = paddle.to_tensor([1, 5, 2], 'float64')
z = paddle.add(x, y)
print(z) # [3., 8., 6. ]
Args:
x (Tensor) – (Variable), Tensor or LoDTensor of any dimensions. Its dtype should be int32, int64, float32, float64.
y (Tensor) – (Variable), Tensor or LoDTensor of any dimensions. Its dtype should be int32, int64, float32, float64.
with_quant_attr (BOOLEAN) – Whether the operator has attributes used by quantization.
name (string, optional) – Name of the output. Default is None. It’s used to print debug info for developers. Details: :ref:`api_guide_Name`

Returns:
N-dimension tensor. A location into which the result is stored. It’s dimension equals with x

Examples:

.. code-block:: python

import paddle

x = paddle.to_tensor([2, 3, 4], 'float64')
y = paddle.to_tensor([1, 5, 2], 'float64')
z = paddle.add(x, y)
print(z) # [3., 8., 6. ]
"""

if in_dygraph_mode():
Expand Down
10 changes: 5 additions & 5 deletions python/paddle/tensor/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -589,18 +589,18 @@ def where(condition, x=None, y=None, name=None):
Tensor: A Tensor with the same shape as :attr:`condition` and same data type as :attr:`x` and :attr:`y`.

Examples:

.. code-block:: python
:name:where-example

import paddle

x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2])
y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0])

out = paddle.where(x>1, x, y)

print(out)
#out: [1.0, 1.0, 3.2, 1.2]

out = paddle.where(x>1)
print(out)
#out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True,
Expand Down
2 changes: 2 additions & 0 deletions python/paddle/tensor/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def numel(x, name=None):

Args:
x (Tensor): The input Tensor, it's data type can be bool, float16, 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:
Tensor: The number of elements for the input Tensor.
Expand Down