未验证 提交 fc6fed32 编写于 作者: W wangchaochaohu 提交者: GitHub

(Variable --->Tensor) refine the OP doc for API2.0 (#25737)

上级 32b9577b
......@@ -263,28 +263,25 @@ def cast(x, dtype):
def concat(input, axis=0, name=None):
"""
:alias_main: paddle.concat
:alias: paddle.concat,paddle.tensor.concat,paddle.tensor.manipulation.concat
This OP concatenates the input along the axis.
Args:
input(list): List of input Tensors with data type float16, float32, float64, int32,
int64. All the Tensors in ``input`` must have the same data type.
axis(int|Variable, optional): Specify the axis to operate on the input Tensors.
It's a scalar with type ``int`` or a ``Tensor`` with shape [1] and data type ``int32`` or ``int64``.
axis(int|Tensor, optional): Specify the axis to operate on the input Tensors.
It's a scalar with data type int or a Tensor with shape [1] and data type int32 or int64.
The effective range is [-R, R), where R is Rank(x). When ``axis < 0``, it works the same way
as axis+R. Default is 0.
as ``axis+R``. Default is 0.
name (str, optional): The default value is None. Normally there is no
need for user to set this property. For more information, please
refer to :ref:`api_guide_Name`.
Raises:
TypeError: The dtype of input must be one of float16, float32, float64, int32 and int64.
TypeError: The ``axis`` must be int or Variable. The dtype of ``axis`` must be int32 or int64 when it's a Tensor.
TypeError: The dtype of ``input`` must be one of float16, float32, float64, int32 and int64.
TypeError: The ``axis`` must be int or Tensor. The dtype of ``axis`` must be int32 or int64 when it's a Tensor.
TypeError: All the Tensors in ``input`` must have the same data type.
Returns:
Variable: A Tensor with the same data type as ``input``.
Tensor: A Tensor with the same data type as ``input``.
Examples:
.. code-block:: python
......@@ -633,8 +630,7 @@ def assign(input, output=None):
def fill_constant(shape, dtype, value, force_cpu=False, out=None, name=None):
"""
:alias_main: paddle.fill_constant
:alias: paddle.fill_constant,paddle.tensor.fill_constant,paddle.tensor.creation.fill_constant
:old_api: paddle.fluid.layers.fill_constant
:alias: paddle.tensor.fill_constant, paddle.tensor.creation.fill_constant
This OP creates a Tensor with specified `shape` and `dtype`, and
initializes it with a constant specified by `value`.
......@@ -642,47 +638,47 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None, name=None):
The attribute `stop_gradient` of the created Tensor is set to True.
Args:
shape(list|tuple|Variable): Shape of the Tensor to be created.
The data type is ``int32`` or ``int64`` . If ``shape`` is a list or tuple,
the elements of it should be integers or Tensors with shape [1].
If ``shape`` is an Variable, it should be an 1-D Tensor .
dtype(np.dtype|core.VarDesc.VarType|str): Data type of the output tensor which can
shape(list|tuple|Tensor): Shape of the output Tensor, the data type of ``shape`` is int32 or int64.
If ``shape`` is a list or tuple, the elements of it should be integers or Tensors with shape [1].
If ``shape`` is an Tensor, it should be an 1-D Tensor with date type int32 or int64.
dtype(np.dtype|core.VarDesc.VarType|str): Data type of the output Tensor which can
be float16, float32, float64, int32, int64.
value(bool|float|int|Variable): The constant value used to initialize
the Tensor to be created. If value is an Variable, it should be an 1-D Tensor.
force_cpu(bool): data should be on CPU if it's true, default value is False.
out(Variable, optional): Optional output which can be any created
Variable that meets the requirements to store the result of operation.
if out is None, a new Varibale will be create to store the result.
value(bool|float|int|Tensor): The constant value used to initialize
the Tensor to be created. If ``value`` is an Tensor, it should be an 1-D Tensor.
force_cpu(bool, optional): data should be on CPU if it's true, default value is False.
out(Tensor, optional): Optional output which can be any created
Tensor that meets the requirements to store the result of operation.
if ``out`` is None, a new Tensor will be create to store the result.
name(str, optional): The default value is None. Normally there is no need for user to set this
property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
Variable: Tensor which is created according to shape and dtype.
Tensor: Tensor which is created according to shape and dtype.
Raises:
TypeError: The dtype must be one of bool, float16, float32, float64, int32 and int64
and the data type of out Tensor must be the same as the dtype.
TypeError: The shape must be one of list, tuple and Variable.
and the data type of ``out`` must be the same as the ``dtype``.
TypeError: The shape must be one of list, tuple and Tensor, the data type of ``shape``
must be int32 or int64 when ``shape`` is a Tensor
Examples:
.. code-block:: python
import paddle.fluid as fluid
# attr shape is a list which doesn't contain Variable Tensor.
# attr shape is a list which doesn't contain Tensor.
data1 = fluid.layers.fill_constant(shape=[2,1], value=0, dtype='int64') # data1=[[0],[0]]
data2 = fluid.layers.fill_constant(shape=[2,1], value=5, dtype='int64', out=data1)
# data1=[[5], [5]] data2=[[5], [5]]
# attr shape is a list which contains Variable Tensor.
# attr shape is a list which contains Tensor.
positive_2 = fluid.layers.fill_constant([1], "int32", 2)
data3 = fluid.layers.fill_constant(shape=[1, positive_2], dtype='float32', value=1.5) # data3=[[1.5, 1.5]]
# attr shape is an Variable Tensor.
# attr shape is a Tensor.
shape = fluid.layers.fill_constant([2], "int32", 2) # shape=[2,2]
data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]]
# attr value is an Variable Tensor.
# attr value is a Tensor.
val = fluid.layers.fill_constant([1], "float32", 2.0) # val=[2.0]
data5 = fluid.layers.fill_constant(shape=[2,1], value=val, dtype='float32') #data5=[[2.0],[2.0]]
"""
......@@ -1039,28 +1035,31 @@ def ones(shape, dtype, force_cpu=False):
Its :attr:`stop_gradient` will be set to True to stop gradient computation.
Parameters:
shape (tuple|list): Shape of output tensor.
dtype (np.dtype|core.VarDesc.VarType|str): Data type of output tensor, it supports
shape(tuple|list|Tensor): Shape of output Tensor, the data type of shape is int32 or int64.
dtype (np.dtype|core.VarDesc.VarType|str): Data type of output Tensor, it supports
bool, float16, float32, float64, int32 and int64.
force_cpu (bool, optional): Whether force to store the output tensor in CPU memory.
If :attr:`force_cpu` is False, the output tensor will be stored in running device memory.
force_cpu (bool, optional): Whether force to store the output Tensor in CPU memory.
If :attr:`force_cpu` is False, the output Tensor will be stored in running device memory.
Default: False.
Returns:
Variable: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 1.
Tensor: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 1.
Raises:
TypeError: The ``dtype`` must be one of bool, float16, float32, float64, int32, int64 and None
and the data type of out Tensor must be the same as the dtype.
TypeError: The ``shape`` must be one of list, tuple and Tensor. The data type of ``shape`` must
be int32 or int64 when it's a Tensor.
Examples:
.. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.ones(shape=[2, 4], dtype='float32') # [[1., 1., 1., 1.], [1., 1., 1., 1.]]
data0 = fluid.layers.ones(shape=[2, 4], dtype='float32') # [[1., 1., 1., 1.], [1., 1., 1., 1.]]
# shape is a Tensor
shape = fluid.layers.fill_constant(shape=[2], dtype='int32', value=2)
data1 = fluid.layers.ones(shape=shape, dtype='int32') #[[1, 1], [1, 1]]
"""
check_type(shape, 'shape', (list, tuple), 'ones')
check_dtype(dtype, 'create data type',
['bool', 'float16', 'float32', 'float64', 'int32', 'int64'],
'ones')
assert reduce(lambda x, y: x * y,
shape) > 0, "The shape is invalid: %s." % (str(shape))
return fill_constant(value=1.0, **locals())
......@@ -1070,23 +1069,32 @@ def zeros(shape, dtype, force_cpu=False, name=None):
Its :attr:`stop_gradient` will be set to True to stop gradient computation.
Parameters:
shape (tuple|list): Shape of output tensor.
dtype (np.dtype|core.VarDesc.VarType|str): Data type of output tensor, it supports
shape(tuple|list|Tensor): Shape of output Tensor, the data type of ``shape`` is int32 or int64.
dtype (np.dtype|core.VarDesc.VarType|str): Data type of output Tensor, it supports
bool, float16, float32, float64, int32 and int64.
force_cpu (bool, optional): Whether force to store the output tensor in CPU memory.
If :attr:`force_cpu` is False, the output tensor will be stored in running device memory.
force_cpu (bool, optional): Whether force to store the output Tensor in CPU memory.
If :attr:`force_cpu` is False, the output Tensor will be stored in running device memory.
Default: False.
name(str, optional): The default value is None. Normally there is no need for user to set this
property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
Variable: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.
Tensor: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.
Raises:
TypeError: The ``dtype`` must be one of bool, float16, float32, float64, int32, int64 and None
and the data type of out Tensor must be the same as the dtype.
TypeError: The ``shape`` must be one of list, tuple and Tensor. The data type of ``shape`` must
be int32 or int64 when it's a Tensor.
Examples:
.. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.zeros(shape=[3, 2], dtype='float32') # [[0., 0.], [0., 0.], [0., 0.]]
# shape is a Tensor
shape = fluid.layers.fill_constant(shape=[2], dtype='int32', value=2)
data1 = fluid.layers.zeros(shape=shape, dtype='int32') #[[0, 0], [0, 0]]
"""
return fill_constant(value=0.0, **locals())
......@@ -1422,26 +1430,26 @@ def linspace(start, stop, num, dtype=None, name=None):
This OP return fixed number of evenly spaced values within a given interval.
Args:
start(float|Variable): The input :attr:`start` is start variable of range. It is a float scalar, \
or a tensor of shape [1] with input data type float32, float64.
stop(float|Variable): The input :attr:`stop` is start variable of range. It is a float scalar, \
or a tensor of shape [1] with input data type float32, float64.
num(int|Variable): The input :attr:`num` is given num of the sequence. It is an int scalar, \
or a tensor of shape [1] with type int32.
dtype(np.dtype|core.VarDesc.VarType|str): The data type of output tensor, it could be 'float32' and 'float64'.
Default: if None, the data type is `float32`.
start(float|Tensor): The input :attr:`start` is start variable of range. It is a float scalar, \
or a Tensor of shape [1] with input data type float32, float64.
stop(float|Tensor): The input :attr:`stop` is start variable of range. It is a float scalar, \
or a Tensor of shape [1] with input data type float32, float64.
num(int|Tensor): The input :attr:`num` is given num of the sequence. It is an int scalar, \
or a Tensor of shape [1] with data type int32.
dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of output tensor, it could be 'float32' and 'float64'.
Default: if None, the data type is float32.
name(str, optional): Normally there is no need for user to set this property.
For more information, please refer to :ref:`api_guide_Name`.Default: None.
Returns:
Variable, the output data type will be float32, float64.: The 1-D tensor with fixed number of evenly spaced values, \
Tensor: the output data type will be float32, float64. The 1-D tensor with fixed number of evenly spaced values, \
the data shape of this tensor is :math:`[num]` . If the :attr:`num` is set 1, the output tensor just has \
the value with input :attr:`start`.
Raises:
TypeError: The dtype must be one of float32 and float64.
TypeError: The dtype of `start` and `stop` must be one of float32 and float64.
TypeError: The dtype of `num` must be one of int32 and int64.
TypeError: The ``dtype`` must be one of float32 and float64.
TypeError: The data type of ``start`` and ``stop`` must be one of float32 and float64.
TypeError: The data type of ``num`` must be one of int32 and int64.
Examples:
......@@ -1577,20 +1585,14 @@ def eye(num_rows,
dtype='float32',
name=None):
"""
:alias_main: paddle.eye
:alias: paddle.eye,paddle.tensor.eye,paddle.tensor.creation.eye
:old_api: paddle.fluid.layers.eye
**eye**
This function constructs a or a batch of 2-D tensor with ones on the diagonal and zeros elsewhere.
Args:
num_rows(int): the number of rows in each batch tensor.
num_columns(int, optional): the number of columns in each batch tensor.
If None, default: num_rows.
batch_shape(list(int), optional): If provided, the returned tensor will have a leading
batch size of this shape, default is None.
batch_shape(list, optional): If provided, the returned tensor will have a leading
batch size of this shape, the data type of ``batch_shape`` is int. Default is None.
dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of the returned tensor.
It should be int32, int64, float16, float32, float64, default is 'float32'.
name(str, optional): The default value is None. Normally there is no
......@@ -1598,7 +1600,7 @@ def eye(num_rows,
refer to :ref:`api_guide_Name`.
Returns:
Variable: An identity Tensor or LoDTensor of shape batch_shape + [num_rows, num_columns].
Tensor: An identity Tensor or LoDTensor of shape batch_shape + [num_rows, num_columns].
Raises:
TypeError: The `dtype` must be one of float16, float32, float64, int32 and int64.
TypeError: The `num_columns` must be non-negative int.
......
......@@ -58,25 +58,25 @@ __all__ = [
def full_like(x, fill_value, dtype=None, name=None):
"""
:alias_main: paddle.full_like
:alias: paddle.full_like,paddle.tensor.full_like,paddle.tensor.creation.full_like
:alias: paddle.tensor.full_like, paddle.tensor.creation.full_like
**full_like**
This function creates a tensor filled with `fill_value` which has identical shape and dtype
with `input`.
This function creates a tensor filled with ``fill_value`` which has identical shape of ``x`` and ``dtype``.
If the ``dtype`` is None, the data type of Tensor is same with ``x``.
Args:
x(Variable): The input tensor which specifies shape and data type. The data type can be bool, float16, float32, float64, int32, int64.
fill_value(bool|float|int|Variable): The value to fill the tensor with. Note: this value shouldn't exceed the range of the output data type.
x(Tensor): The input tensor which specifies shape and data type. The data type can be bool, float16, float32, float64, int32, int64.
fill_value(bool|float|int): The value to fill the tensor with. Note: this value shouldn't exceed the range of the output data type.
dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of output. The data type can be one
of bool, float16, float32, float64, int32, int64. The default value is None, which means the output
data type is the same as input.
name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns:
out(Variable): The Tensor variable storing the output.
Tensor: Tensor which is created according to ``x``, ``fill_value`` and ``dtype``.
Raises:
TypeError: The dtype must be one of bool, float16, float32, float64, int32, int64 and None.
TypeError: The data type of ``x`` must be one of bool, float16, float32, float64, int32, int64.
TypeError: The ``dtype`` must be one of bool, float16, float32, float64, int32, int64 and None.
Examples:
.. code-block:: python
......@@ -101,6 +101,9 @@ def full_like(x, fill_value, dtype=None, name=None):
return core.ops.fill_any_like(x, 'value', fill_value, 'dtype', dtype)
helper = LayerHelper("full_like", **locals())
check_variable_and_dtype(
x, 'x', ['bool', 'float16', 'float32', 'float64', 'int32', 'int64'],
'full_like')
check_dtype(dtype, 'dtype',
['bool', 'float16', 'float32', 'float64', 'int32', 'int64'],
'full_like/zeros_like/ones_like')
......@@ -119,23 +122,24 @@ def full_like(x, fill_value, dtype=None, name=None):
def ones(shape, dtype=None, name=None):
"""
:alias_main: paddle.ones
:alias: paddle.ones,paddle.tensor.ones,paddle.tensor.creation.ones
:alias: paddle.tensor.ones, paddle.tensor.creation.ones
The OP creates a tensor of specified :attr:`shape` and :attr:`dtype`, and fills it with 1.
Args:
shape(tuple|list|Variable): Shape of output tensor, the data type of shape is int32 or int64.
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of output tensor, it supports
shape(tuple|list|Tensor): Shape of the Tensor to be created, the data type of shape is int32 or int64.
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of output Tensor, it supports
bool, float16, float32, float64, int32 and int64. Default: if None, the data type is 'float32'.
name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns:
Variable: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 1.
Tensor: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 1.
Raises:
TypeError: The dtype must be one of bool, float16, float32, float64, int32, int64 and None
TypeError: The ``dtype`` must be one of bool, float16, float32, float64, int32, int64 and None
and the data type of out Tensor must be the same as the dtype.
TypeError: The `shape` must be one of list, tuple and Variable.
TypeError: The ``shape`` must be one of list, tuple and Tensor. The data type of ``shape`` must
be int32 or int64 when it's a Tensor.
Examples:
.. code-block:: python
......@@ -143,7 +147,7 @@ def ones(shape, dtype=None, name=None):
import paddle
paddle.enable_imperative()
#default dtype for ones OP
# default dtype for ones OP
data1 = paddle.ones(shape=[3, 2])
# [[1. 1.]
# [1. 1.]
......@@ -153,7 +157,7 @@ def ones(shape, dtype=None, name=None):
# [[1 1]
# [1 1]]
#shape is a Variable
# shape is a Tensor
shape = paddle.fill_constant(shape=[2], dtype='int32', value=2)
data3 = paddle.ones(shape=shape, dtype='int32')
# [[1 1]
......@@ -210,28 +214,45 @@ def ones_like(x, dtype=None, name=None):
def zeros(shape, dtype=None, name=None):
"""
:alias_main: paddle.zeros
:alias: paddle.zeros,paddle.tensor.zeros,paddle.tensor.creation.zeros
:alias: paddle.tensor.zeros, paddle.tensor.creation.zeros
The OP creates a tensor of specified :attr:`shape` and :attr:`dtype`, and fills it with 0.
Args:
shape(tuple|list|Variable): Shape of output tensor. The data type of shape is int32 or int64.
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of output tensor, it supports
shape(tuple|list|Tensor): Shape of the Tensor to be created, the data type of ``shape`` is int32 or int64.
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of output Tensor, it supports
bool, float16, float32, float64, int32 and int64. Default: if None, the date type is float32.
name(str, optional): The default value is None. Normally there is no need for user to set this
property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
Variable: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.
Tensor: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.
Raises:
TypeError: The ``dtype`` must be one of bool, float16, float32, float64, int32, int64 and None
and the data type of out Tensor must be the same as the dtype.
TypeError: The ``shape`` must be one of list, tuple and Tensor. The data type of ``shape`` must
be int32 or int64 when it's a Tensor.
Examples:
.. code-block:: python
import paddle
paddle.enable_imperative() # Now we are in imperative mode
data = paddle.zeros(shape=[3, 2], dtype='float32') # [[0., 0.], [0., 0.], [0., 0.]]
data = paddle.zeros(shape=[2, 2], dtype='int32', name='zeros') # [[0, 0], [0, 0]]
data = paddle.zeros(shape=[3, 2], dtype='float32')
# [[0. 0.]
# [0. 0.]
# [0. 0.]]
data = paddle.zeros(shape=[2, 2])
# [[0. 0.]
# [0. 0.]]
# shape is a Tensor
shape = paddle.fill_constant(shape=[2], dtype='int32', value=2)
data3 = paddle.ones(shape=shape, dtype='int32')
# [[0 0]
# [0 0]]
"""
if dtype is None:
dtype = 'float32'
......@@ -283,27 +304,31 @@ def zeros_like(x, dtype=None, name=None):
def eye(num_rows, num_columns=None, dtype=None, name=None):
"""
:alias_main: paddle.eye
:alias: paddle.tensor.eye, paddle.tensor.creation.eye
This function constructs 2-D Tensor with ones on the diagonal and zeros elsewhere.
Args:
num_rows(int): the number of rows in each batch tensor.
num_columns(int, optional): the number of columns in each batch tensor.
num_rows(int): the number of rows in each batch Tensor.
num_columns(int, optional): the number of columns in each batch Tensor.
If None, default: num_rows.
dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of the returned tensor.
dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of the returned Tensor.
It should be int32, int64, float16, float32, float64. Default: if None, the data type
is float32.
name(str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns:
Variable: An identity Tensor or LoDTensor of shape [num_rows, num_columns].
Tensor: An identity Tensor or LoDTensor of shape [num_rows, num_columns].
Raises:
TypeError: The `dtype` must be one of float16, float32, float64, int32 int64 and None.
TypeError: The `num_columns` must be non-negative int.
TypeError: The ``dtype`` must be one of float16, float32, float64, int32 int64 and None.
TypeError: The ``num_columns`` must be non-negative int.
Examples:
.. code-block:: python
import paddle
paddle.enable_imperative() # Now we are in imperative mode
......@@ -330,29 +355,30 @@ def eye(num_rows, num_columns=None, dtype=None, name=None):
def full(shape, fill_value, dtype=None, name=None):
"""
:alias_main: paddle.full
:alias: paddle.full,paddle.tensor.full,paddle.tensor.creation.full
:alias: paddle.tensor.full, paddle.tensor.creation.full
This Op return a Tensor with the `fill_value` which size is same as `shape`
This Op return a Tensor with the ``fill_value`` which size is same as ``shape``.
Args:
shape(list|tuple|Variable): Shape of the Tensor to be created.
shape(list|tuple|Tensor): Shape of the Tensor to be created.
The data type is ``int32`` or ``int64`` . If ``shape`` is a list or tuple,
the elements of it should be integers or Tensors with shape [1].
If ``shape`` is an Variable, it should be an 1-D Tensor .
fill_value(bool|float16|float32|float64|int32|int64|Variable): The constant value
used to initialize the Tensor to be created. If fill_value is an Variable, it must be an 1-D Tensor.
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of the output tensor
If ``shape`` is an Tensor, it should be an 1-D Tensor .
fill_value(bool|float|int|Tensor): The constant value
used to initialize the Tensor to be created. If ``fill_value`` is an Tensor, it must be an 1-D Tensor.
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of the output Tensor
which can be float16, float32, float64, int32, int64, if dytpe is `None`, the data
type of created tensor is `float32`
type of created Tensor is `float32`
name(str, optional): The default value is None. Normally there is no need for user to set this
property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
Variable: Tensor which is created according to shape and dtype.
Tensor: Tensor which is created according to ``shape``, ``fill_value`` and ``dtype``.
Raises:
TypeError: The `dtype` must be one of None, bool, float16, float32, float64, int32 and int64.
TypeError: The `shape` must be one of Variable, list and tuple.
TypeError: The ``dtype`` must be one of None, bool, float16, float32, float64, int32 and int64.
TypeError: The ``shape`` must be one of Tensor, list and tuple. The data type of ``shape`` must
be int32 or int64 when the it's a Tensor
Examples:
.. code-block:: python
......@@ -364,18 +390,18 @@ def full(shape, fill_value, dtype=None, name=None):
#[[0]
# [0]]
# attr shape is a list which contains Variable Tensor.
# attr shape is a list which contains Tensor.
positive_2 = paddle.fill_constant([1], "int32", 2)
data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5)
# [[1.5 1.5]]
# attr shape is an Variable Tensor.
# attr shape is a Tensor.
shape = paddle.fill_constant([2], "int32", 2)
data4 = paddle.full(shape=shape, dtype='bool', fill_value=True)
# [[True True]
# [True True]]
# attr fill_value is an Variable Tensor.
# attr fill_value is a Tensor.
val = paddle.fill_constant([1], "float32", 2.0)
data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32')
# [[2.0]
......
......@@ -54,27 +54,27 @@ __all__ = [
def concat(x, axis=0, name=None):
"""
:alias_main: paddle.concat
:alias: paddle.concat,paddle.tensor.concat,paddle.tensor.manipulation.concat
:alias: paddle.tensor.concat, paddle.tensor.manipulation.concat
This OP concatenates the input along the axis.
Args:
x(list): List of input Tensors with data type float16, float32, float64, int32, int64.
All the Tensors in ``x`` must have same data type.
axis(int|Variable, optional): Specify the axis to operate on the input Tensors.
It's a scalar with type ``int`` or a ``Tensor`` with shape [1] and data type ``int32``
or ``int64``. The effective range is [-R, R), where R is Rank(x). When ``axis < 0``,
it works the same way as axis+R. Default is 0.
axis(int|Tensor, optional): Specify the axis to operate on the input Tensors.
It's a scalar with data type int or a Tensor with shape [1] and data type int32
or int64. The effective range is [-R, R), where R is Rank(x). When ``axis < 0``,
it works the same way as ``axis+R``. Default is 0.
name (str, optional): The default value is None. Normally there is no
need for user to set this property. For more information, please
refer to :ref:`api_guide_Name`.
Raises:
TypeError: The dtype of ``x`` must be one of float16, float32, float64, int32 and int64.
TypeError: The ``axis`` must be int or Variable. The dtype of ``axis`` must be int32 or int64 when it's a Tensor.
TypeError: The ``axis`` must be int or Tensor. The dtype of ``axis`` must be int32 or int64 when it's a Tensor.
TypeError: All the Tensors in ``x`` must have the same data type.
Returns:
Variable: A Tensor with the same data type as ``x``.
Tensor: A Tensor with the same data type as ``x``.
Examples:
.. code-block:: python
......
......@@ -223,27 +223,27 @@ def argmax(input, axis=None, dtype=None, out=None, keepdims=False, name=None):
def index_select(x, index, axis=0, name=None):
"""
:alias_main: paddle.index_select
:alias: paddle.index_select,paddle.tensor.index_select,paddle.tensor.search.index_select
:alias: paddle.tensor.index_select, paddle.tensor.search.index_select
Returns a new tensor which indexes the `input` tensor along dimension `dim` using
the entries in `index` which is a Tensor. The returned tensor has the same number
of dimensions as the original `input` tensor. The dim-th dimension has the same
size as the length of `index`; other dimensions have the same size as in the `input` tensor.
Returns a new tensor which indexes the ``input`` tensor along dimension ``axis`` using
the entries in ``index`` which is a Tensor. The returned tensor has the same number
of dimensions as the original ``x`` tensor. The dim-th dimension has the same
size as the length of ``index``; other dimensions have the same size as in the ``x`` tensor.
Args:
x (Variable): The input tensor variable.The dtype of x can be one of float32, float64, int32, int64.
index (Variable): The 1-D tensor containing the indices to index.the dtype of index can be int32 or int64.
axis (int, optional): The dimension in which we index. Default: if None, the axis is 0.
x (Tensor): The input Tensor to be operated. The data of ``x`` can be one of float32, float64, int32, int64.
index (Tensor): The 1-D Tensor containing the indices to index. The data type of ``index`` must be int32 or int64.
axis (int, optional): The dimension in which we index. Default: if None, the ``axis`` is 0.
name(str, optional): The default value is None. Normally there is no
need for user to set this property. For more information, please
refer to :ref:`api_guide_Name`.
Returns:
Variable: A Tensor with same data type as `input`.
Tensor: A Tensor with same data type as ``x``.
Raises:
TypeError: x must be a Variable and the dtype of x must be one of float32, float64, int32 and int64.
TypeError: index must be a Variable adn the dtype of index must be int32 or int64.
TypeError: ``x`` must be a Tensor and the data type of ``x`` must be one of float32, float64, int32 and int64.
TypeError: ``index`` must be a Tensor and the data type of ``index`` must be int32 or int64.
Examples:
.. code-block:: python
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册