update api parameters

This commit is contained in:
shaojunsong 2023-03-04 10:41:34 +08:00
parent ba0775661f
commit 0e8045898a
7 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,6 @@
mindspore.Tensor.mean
=====================
.. py:method:: mindspore.Tensor.mean(axis=(), keep_dims=False)
.. py:method:: mindspore.Tensor.mean(axis=None, keep_dims=False)
详情请参考 :func:`mindspore.ops.mean`

View File

@ -1,6 +1,6 @@
mindspore.Tensor.prod
=====================
.. py:method:: mindspore.Tensor.prod(axis=(), keep_dims=False)
.. py:method:: mindspore.Tensor.prod(axis=None, keep_dims=False)
详情请参考 :func:`mindspore.ops.prod`

View File

@ -1,19 +1,19 @@
mindspore.ops.mean
==================
.. py:function:: mindspore.ops.mean(x, axis=(), keep_dims=False)
.. py:function:: mindspore.ops.mean(x, axis=None, keep_dims=False)
默认情况下,移除输入所有维度,返回 `x` 中所有元素的平均值。也可仅缩小指定维度 `axis` 大小至1。 `keep_dims` 控制输出和输入的维度是否相同。
参数:
- **x** (Tensor[Number]) - 输入Tensor其数据类型为数值型。shape :math:`(N, *)` ,其中 :math:`*` 表示任意数量的附加维度。秩应小于8。
- **axis** (Union[int, tuple(int), list(int)]) - 要减少的维度。默认值: (),缩小所有维度。只允许常量值。假设 `x` 的秩为r取值范围[-r,r)。
- **axis** (Union[int, tuple(int), list(int)]) - 要减少的维度。默认值: None,缩小所有维度。只允许常量值。假设 `x` 的秩为r取值范围[-r,r)。
- **keep_dims** (bool) - 如果为True则保留缩小的维度大小为1。否则移除维度。默认值False。
返回:
Tensor。
- 如果 `axis`(),且 `keep_dims` 为False则输出一个零维Tensor表示输入Tensor中所有元素的平均值。
- 如果 `axis`None,且 `keep_dims` 为False则输出一个零维Tensor表示输入Tensor中所有元素的平均值。
- 如果 `axis` 为int取值为1并且 `keep_dims` 为False则输出的shape为 :math:`(x_0, x_2, ..., x_R)`
- 如果 `axis` 为tuple(int)或list(int),取值为(1, 2),并且 `keep_dims` 为False则输出Tensor的shape为 :math:`(x_0, x_3, ..., x_R)`

View File

@ -1,19 +1,19 @@
mindspore.ops.prod
==================
.. py:function:: mindspore.ops.prod(x, axis=(), keep_dims=False)
.. py:function:: mindspore.ops.prod(x, axis=None, keep_dims=False)
默认情况下使用指定维度的所有元素的乘积代替该维度的其他元素以移除该维度。也可仅缩小该维度大小至1。 `keep_dims` 控制输出和输入的维度是否相同。
参数:
- **x** (Tensor[Number]) - 输入Tensor其数据类型为数值型。shape :math:`(N, *)` ,其中 :math:`*` 表示任意数量的附加维度。秩应小于8。
- **axis** (Union[int, tuple(int), list(int)]) - 要减少的维度。默认值: (),缩小所有维度。只允许常量值。假设 `x` 的秩为r取值范围[-r,r)。
- **axis** (Union[int, tuple(int), list(int)]) - 要减少的维度。默认值: None,缩小所有维度。只允许常量值。假设 `x` 的秩为r取值范围[-r,r)。
- **keep_dims** (bool) - 如果为True则保留缩小的维度大小为1。否则移除维度。默认值False。
返回:
Tensor。
- 如果 `axis`(),且 `keep_dims` 为False则输出一个零维Tensor表示输入Tensor中所有元素的乘积。
- 如果 `axis`None,且 `keep_dims` 为False则输出一个零维Tensor表示输入Tensor中所有元素的乘积。
- 如果 `axis` 为int取值为1并且 `keep_dims` 为False则输出的shape为 :math:`(x_0, x_2, ..., x_R)`
- 如果 `axis` 为tuple(int)或list(int),取值为(1, 2),并且 `keep_dims` 为False则输出Tensor的shape为 :math:`(x_0, x_3, ..., x_R)`

View File

@ -68,7 +68,7 @@ itemsize_map = {mstype.bool_: 1, mstype.int8: 1, mstype.uint8: 1,
nan_tensor = Tensor(float('nan'), dtype=mstype.float32)
def mean(x, axis=(), keep_dims=False):
def mean(x, axis=None, keep_dims=False):
"""
Reduces a dimension of a tensor by averaging all elements in the dimension.
@ -102,14 +102,14 @@ def ndimension(x):
return len(x.shape)
def prod(x, axis=(), keep_dims=False):
def prod(x, axis=None, keep_dims=False):
"""
Reduces a dimension of a tensor by product all elements in the dimension.
Args:
x (Tensor): Input Tensor.
axis (Union[None, int, tuple(int), list(int)]): Dimensions of reduction,
when axis is None or empty tuple, reduce all dimensions. Default: ().
when axis is None or empty tuple, reduce all dimensions. Default: None.
keep_dims (bool): Whether to keep the reduced dimensions. Default: False.
Returns:

View File

@ -1423,7 +1423,7 @@ class Tensor(Tensor_, metaclass=_TensorMeta):
self._init_check()
return tensor_operator_registry.get('log2')(self)
def mean(self, axis=(), keep_dims=False):
def mean(self, axis=None, keep_dims=False):
"""
For details, please refer to :func:`mindspore.ops.mean`.
"""
@ -1437,8 +1437,6 @@ class Tensor(Tensor_, metaclass=_TensorMeta):
For details, please refer to :func:`mindspore.ops.amin`.
"""
self._init_check()
if axis is None:
axis = ()
return tensor_operator_registry.get('amin')(self, axis, keep_dims)
def reverse(self, axis):
@ -1453,8 +1451,6 @@ class Tensor(Tensor_, metaclass=_TensorMeta):
For details, please refer to :func:`mindspore.ops.amax`.
"""
self._init_check()
if axis is None:
axis = ()
return tensor_operator_registry.get('amax')(self, axis, keep_dims)
def reverse_sequence(self, seq_lengths, seq_dim=0, batch_dim=0):
@ -1464,7 +1460,7 @@ class Tensor(Tensor_, metaclass=_TensorMeta):
self._init_check()
return tensor_operator_registry.get("reverse_sequence")(seq_dim, batch_dim)(self, seq_lengths)
def prod(self, axis=(), keep_dims=False):
def prod(self, axis=None, keep_dims=False):
"""
For details, please refer to :func:`mindspore.ops.prod`.
"""

View File

@ -7117,7 +7117,7 @@ def amax(input, axis=None, keep_dims=False):
return _get_cache_prim(P.ReduceMax)(keep_dims)(input, axis)
def mean(x, axis=(), keep_dims=False):
def mean(x, axis=None, keep_dims=False):
r"""
Reduces all dimension of a tensor by averaging all elements in the dimension, by default.
And reduce a dimension of `x` along the specified `axis`. `keep_dims`
@ -7126,7 +7126,7 @@ def mean(x, axis=(), keep_dims=False):
Args:
x (Tensor[Number]): The input tensor. The dtype of the tensor to be reduced is number.
:math:`(N,*)` where :math:`*` means, any number of additional dimensions, its rank should be less than 8.
axis (Union[int, tuple(int), list(int)]): The dimensions to reduce. Default: (), reduce all dimensions.
axis (Union[int, tuple(int), list(int)]): The dimensions to reduce. Default: None, reduce all dimensions.
Only constant value is allowed. Assume the rank of `x` is r, and the value range is [-r,r).
keep_dims (bool): If true, keep these reduced dimensions and the length is 1.
If false, don't keep these dimensions. Default: False.
@ -7134,7 +7134,7 @@ def mean(x, axis=(), keep_dims=False):
Returns:
Tensor, has the same data type as input tensor.
- If `axis` is (), and `keep_dims` is False,
- If `axis` is None, and `keep_dims` is False,
the output is a 0-D tensor representing the product of all elements in the input tensor.
- If `axis` is int, set as 1, and `keep_dims` is False,
the shape of output is :math:`(x_0, x_2, ..., x_R)`.
@ -7191,11 +7191,12 @@ def mean(x, axis=(), keep_dims=False):
[ 8.]
[10.]]]
"""
if axis is None:
axis = ()
return _get_cache_prim(P.ReduceMean)(keep_dims)(x, axis)
def prod(x, axis=(), keep_dims=False):
def prod(x, axis=None, keep_dims=False):
r"""
Reduces a dimension of a tensor by multiplying all elements in the dimension, by default. And also can
reduce a dimension of `x` along the axis. Determine whether the dimensions of the output and input are the same by
@ -7204,7 +7205,7 @@ def prod(x, axis=(), keep_dims=False):
Args:
x (Tensor[Number]): The input tensor. The dtype of the tensor to be reduced is number.
:math:`(N,*)` where :math:`*` means, any number of additional dimensions, its rank should be less than 8.
axis (Union[int, tuple(int), list(int)]): The dimensions to reduce. Default: (), reduce all dimensions.
axis (Union[int, tuple(int), list(int)]): The dimensions to reduce. Default: None, reduce all dimensions.
Only constant value is allowed. Assume the rank of `x` is r, and the value range is [-r,r).
keep_dims (bool): If true, keep these reduced dimensions and the length is 1.
If false, don't keep these dimensions. Default: False.
@ -7212,7 +7213,7 @@ def prod(x, axis=(), keep_dims=False):
Returns:
Tensor, has the same data type as input tensor.
- If `axis` is (), and `keep_dims` is False,
- If `axis` is None, and `keep_dims` is False,
the output is a 0-D tensor representing the product of all elements in the input tensor.
- If `axis` is int, set as 1, and `keep_dims` is False,
the shape of output is :math:`(x_0, x_2, ..., x_R)`.
@ -7268,6 +7269,8 @@ def prod(x, axis=(), keep_dims=False):
[2.62144e+05]
[5.31441e+05]]]
"""
if axis is None:
axis = ()
return _get_cache_prim(P.ReduceProd)(keep_dims)(x, axis)