!49691 fixed_std_mean

Merge pull request !49691 from yide12/tensor_nansum_master
This commit is contained in:
i-robot 2023-03-06 01:31:54 +00:00 committed by Gitee
commit 40cf634c51
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 32 additions and 21 deletions

View File

@ -11,7 +11,7 @@ mindspore.ops.std
参数:
- **input** (Tensor[Number]) - 输入Tensor其数据类型为数值型。shape :math:`(N, *)` ,其中 :math:`*` 表示任意数量的附加维度。秩应小于8。
- **axis** (Union[int, tuple(int), list(int)],可选) - 要减少的维度。只允许常量值。假设 `input` 的秩为r取值范围[-r,r)。默认值: None缩小所有维度。
- **ddof** (Union[int, bool],可选) - δ自由度。如果为整数,计算中使用的除数是 :math:`N - ddof` ,其中 :math:`N` 表示元素的数量。如果为True使用Bessel校正。如果是False使用偏置估计来计算差。默认值0。
- **ddof** (Union[int, bool],可选) - δ自由度。如果为整数,计算中使用的除数是 :math:`N - ddof` ,其中 :math:`N` 表示元素的数量。如果为True使用Bessel校正。如果是False使用偏置估计来计算标准差。默认值0。
- **keepdims** (bool可选) - 是否保留输出Tensor的维度。如果为True则保留缩小的维度大小为1。否则移除维度。默认值False。
返回:

View File

@ -11,9 +11,9 @@ mindspore.ops.std_mean
参数:
- **input** (Tensor[Number]) - 输入Tensor其数据类型为数值型。shape :math:`(N, *)` ,其中 :math:`*` 表示任意数量的附加维度。秩应小于8。
- **axis** (Union[int, tuple(int), list(int)],可选) - 要减少的维度。只允许常量值。假设 `input` 的秩为r取值范围[-r,r)。默认值: None缩小所有维度。
- **ddof** (Union[int, bool],可选) - δ自由度。如果为整数,计算中使用的除数是 :math:`N - ddof` ,其中 :math:`N` 表示元素的数量。如果为True使用Bessel校正。如果是False使用偏置估计来计算差。默认值0。
- **ddof** (Union[int, bool],可选) - δ自由度。如果为整数,计算中使用的除数是 :math:`N - ddof` ,其中 :math:`N` 表示元素的数量。如果为True使用Bessel校正。如果是False使用偏置估计来计算标准差。默认值0。
- **keepdims** (bool可选) - 是否保留输出Tensor的维度。如果为True则保留缩小的维度大小为1。否则移除维度。默认值False。
返回:
包含标准差和均值的tuple。
假设输入 `input` 的shape为 :math:`(x_0, x_1, ..., x_R)`

View File

@ -4708,10 +4708,12 @@ def var(input, axis=None, ddof=0, keepdims=False): # pylint: disable=redefined-o
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> input = Tensor(np.array([[1, 2, 3], [-1, 1, 4]]).astype(np.float32))
>>> output = ops.var(input, 1, True, False)
>>> import mindspore as ms
>>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32)
>>> output = ms.ops.var(input, 1, 2, True)
>>> print(output)
[1. 6.3333325]
[[ 2.5]
[54.5]]
"""
axis = _check_var_std_input(input, ddof, keepdims, axis, "var")
output = var_mean(input, axis, ddof, keepdims)
@ -4737,7 +4739,7 @@ def var_mean(input, axis=None, ddof=0, keepdims=False):
If ddof is an integer, the divisor used in calculations is :math:`N - ddof`,
where :math:`N` represents the number of elements.
If ddof is True, will use the Bessel correction unbiased estimation.
If ddof is False, will through the biased estimation to calculate the variance and mean.
If ddof is False, will through the biased estimation to calculate the variance.
Default: 0.
keepdims (bool, optional): Whether the output Tensor has dim retained or not.
If true, keep these reduced dimensions and the length is 1.
@ -4764,12 +4766,15 @@ def var_mean(input, axis=None, ddof=0, keepdims=False):
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> input = Tensor(np.array([[1, 2, 3], [-1, 1, 4]]).astype(np.float32))
>>> output_var, output_mean = ops.var_mean(input, 1, True, False)
>>> import mindspore as ms
>>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32)
>>> output_var, output_mean = ms.ops.var_mean(input, 1, 2, True)
>>> print(output_var)
[1. 6.3333325]
[[ 2.5]
[54.5]]
>>> print(output_mean)
[2. 1.3333334]
[[ 2.5]
[-1.5]]
"""
axis = _check_var_std_input(input, ddof, keepdims, axis, "var_mean")
if ddof in (0, 1):
@ -4779,13 +4784,14 @@ def var_mean(input, axis=None, ddof=0, keepdims=False):
x_sub = _get_cache_prim(P.Sub)()(input, x_mean)
x_pow = _get_cache_prim(P.Pow)()(x_sub, 2)
x_sum = sum(x_pow, axis, keepdims)
res_mean = mean(input, axis, keepdims)
nums = 1
if axis == ():
nums = input.size
else:
for ax in axis:
nums *= input.shape[ax]
return true_divide(x_sum, nums - ddof), x_mean
return true_divide(x_sum, nums - ddof), res_mean
def std(input, axis=None, ddof=0, keepdims=False):
@ -4833,10 +4839,12 @@ def std(input, axis=None, ddof=0, keepdims=False):
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> input = Tensor(np.array([[1, 2, 3], [-1, 1, 4]]).astype(np.float32))
>>> output = ops.std(input, 1, True, False)
>>> import mindspore as ms
>>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32)
>>> output = ms.ops.std(input, 1, 2, True)
>>> print(output)
[1. 2.5166113]
[[1.5811388]
[7.3824115]]
"""
axis = _check_var_std_input(input, ddof, keepdims, axis, "std")
output = std_mean(input, axis, ddof, keepdims)
@ -4862,7 +4870,7 @@ def std_mean(input, axis=None, ddof=0, keepdims=False):
If ddof is an integer, the divisor used in calculations is :math:`N - ddof`,
where :math:`N` represents the number of elements.
If ddof is True, will use the Bessel correction unbiased estimation.
If ddof is False, will through the biased estimation to calculate the standard deviation and mean.
If ddof is False, will through the biased estimation to calculate the standard deviation.
Default: 0.
keepdims (bool, optional): Whether the output Tensor has dim retained or not.
If true, keep these reduced dimensions and the length is 1.
@ -4889,12 +4897,15 @@ def std_mean(input, axis=None, ddof=0, keepdims=False):
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> input = Tensor(np.array([[1, 2, 3], [-1, 1, 4]]).astype(np.float32))
>>> output_std, output_mean = ops.std_mean(input, 1, True, False)
>>> import mindspore as ms
>>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32)
>>> output_std, output_mean = ms.ops.std_mean(input, 1, 2, True)
>>> print(output_std)
[1. 2.5166113]
[[1.5811388]
[7.3824115]]
>>> print(output_mean)
[2. 1.3333334]
[[ 2.5]
[-1.5]]
"""
axis = _check_var_std_input(input, ddof, keepdims, axis, "std_mean")
if ddof in (0, 1):
@ -9388,7 +9399,7 @@ def einsum(equation, *operands):
You can use this operator to perform diagonal, reducesum, transpose, matmul, mul, inner product operations, etc.
Note:
The sublist format is alse supported. For example, ops.einsum(op1, sublist1, op2, sublist2, ..., sublist_out).
The sublist format is also supported. For example, ops.einsum(op1, sublist1, op2, sublist2, ..., sublist_out).
In this format, equation can be derived by the sublists which are made up of Python's Ellipsis and list of
integers in [0, 52). Each operand is followed by a sublist and an output sublist is at the end.