Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.mint.var

mindspore.mint.var(input, dim=None, *, correction=1, keepdim=False)[source]

Calculates the variance over the dimensions specified by dim. dim can be a single dimension, list of dimensions, or None to reduce over all dimensions.

The variance (δ2) is calculated as:

δ2=1max(0,NδN)i=0N1(xix¯)2

where x is the sample set of elements, x¯ is the sample mean, N is the number of samples and δN is the correction.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – The tensor used to calculate the variance.

  • dim (None, int, tuple(int), optional) – The dimension or dimensions to reduce. Defaults to None. If None, all dimensions are reduced.

Keyword Arguments
  • correction (int, optional) – The difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction. Defaults to 1.

  • keepdim (bool, optional) – 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. Defaults to False.

Returns

Tensor, the variance. Suppose the shape of input is (x0,x1,...,xR):

  • If dim is () and keepdim is set to False , returns a 0-D Tensor, indicating the variance of all elements in input.

  • If dim is int, e.g. 1 and keepdim is set to False , then the returned Tensor has shape (x0,x2,...,xR).

  • If dim is tuple(int) or list(int), e.g. (1, 2) and keepdim is set to False , then the returned Tensor has shape (x0,x3,...,xR).

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If input is not in bfloat16, float16, flaot32.

  • TypeError – If dim is not one of the followings: None, int, list, tuple.

  • TypeError – If correction is not an int.

  • TypeError – If keepdim is not a bool.

  • ValueError – If dim is out of range [input.ndim,input.ndim).

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> from mindspore import Tensor, mint
>>> input = Tensor([[8, 2, 1], [5, 9, 3], [4, 6, 7]], mindspore.float32)
>>> output = mint.var(input, dim=0, correction=1, keepdim=True)
>>> print(output)
[[ 4.333333, 12.333333, 9.333333]]