mindspore.ops.std

mindspore.ops.std(input_x, axis=(), unbiased=True, keep_dims=False)[source]

Returns the standard-deviation and mean of each row of the input tensor by default, or it can calculate them in specified dimension axis. If axis is a list of dimensions, reduce over all of them.

Parameters
  • input_x (Tensor[Number]) – Input tensor with a dtype of number.Number, its shape should be \((N, *)\) where \(*\) means any number of additional dims, its rank should be less than 8.

  • axis (Union[int, tuple(int), list(int)]) – The dimensions to reduce. Default: (), reduce all dimensions. Only constant value is allowed. Must be in the range [-rank(input_x), rank(input_x)).

  • unbiased (bool) – Whether to use Bessel’s correction. If true, will use the Bessel correction unbiased estimation. If false, will through the biased estimation to calculate the standard deviation.

  • keep_dims (bool) – Whether the output tensor has dim retained or not. If true, keep these reduced dimensions and the length is 1. If false, don’t keep these dimensions.

Returns

A tuple of 2 Tensors (output_std, output_mean) containing the standard deviation and mean. Suppose the shape of input_x is \((x_0, x_1, ..., x_R)\):

  • If axis is () and keep_dims is set to False, returns a 0-D Tensor, indicating the standard deviation of all elements in input_x.

  • If axis is int 1 and keep_dims is set to False, then the returned Tensor has shape \((x_0, x_2, ..., x_R)\).

  • If axis is tuple(int) or list(int), e.g. (1, 2) and keep_dims is set to False, then the returned Tensor has shape \((x_0, x_2, ..., x_R)\).

Raises
  • TypeError – If input_x is not a Tensor.

  • TypeError – If axis is not one of the following: int, tuple or list.

  • TypeError – If keep_dims is not a bool.

  • ValueError – If axis is out of range.

Supported Platforms:

Ascend CPU

Examples

>>> input_x = Tensor(np.array([[1, 2, 3], [-1, 1, 4]]).astype(np.float32))
>>> output = ops.std(input_x, 1, True, False)
>>> output_std, output_mean = output[0], output[1]
>>> print(output_std)
[1.        2.5166116]
>>> print(output_mean)
[2.        1.3333334]