Computes the variance of elements across dimensions of a tensor. Reduces `input_tensor` along the dimensions given in `axis`. Unless `keepdims` is true, the rank of the tensor is reduced by 1 for each entry in `axis`. If `keepdims` is true, the reduced dimensions are retained with length 1.
(input_tensor, axis=None, keepdims=False, name=None)
| 1872 | |
| 1873 | @tf_export("math.reduce_variance") |
| 1874 | def reduce_variance(input_tensor, axis=None, keepdims=False, name=None): |
| 1875 | """Computes the variance of elements across dimensions of a tensor. |
| 1876 | |
| 1877 | Reduces `input_tensor` along the dimensions given in `axis`. |
| 1878 | Unless `keepdims` is true, the rank of the tensor is reduced by 1 for each |
| 1879 | entry in `axis`. If `keepdims` is true, the reduced dimensions |
| 1880 | are retained with length 1. |
| 1881 | |
| 1882 | If `axis` is None, all dimensions are reduced, and a |
| 1883 | tensor with a single element is returned. |
| 1884 | |
| 1885 | For example: |
| 1886 | |
| 1887 | ```python |
| 1888 | x = tf.constant([[1., 2.], [3., 4.]]) |
| 1889 | tf.reduce_variance(x) # 1.25 |
| 1890 | tf.reduce_variance(x, 0) # [1., 1.] |
| 1891 | tf.reduce_variance(x, 1) # [0.25, 0.25] |
| 1892 | ``` |
| 1893 | |
| 1894 | Args: |
| 1895 | input_tensor: The tensor to reduce. Should have numeric type. |
| 1896 | axis: The dimensions to reduce. If `None` (the default), reduces all |
| 1897 | dimensions. Must be in the range `[-rank(input_tensor), |
| 1898 | rank(input_tensor))`. |
| 1899 | keepdims: If true, retains reduced dimensions with length 1. |
| 1900 | name: A name scope for the associated operations (optional). |
| 1901 | |
| 1902 | Returns: |
| 1903 | The reduced tensor, of the same dtype as the input_tensor. |
| 1904 | |
| 1905 | @compatibility(numpy) |
| 1906 | Equivalent to np.var |
| 1907 | |
| 1908 | Please note that `np.var` has a `dtype` parameter that could be used to |
| 1909 | specify the output type. By default this is `dtype=float64`. On the other |
| 1910 | hand, `tf.reduce_variance` has an aggressive type inference from |
| 1911 | `input_tensor`, |
| 1912 | @end_compatibility |
| 1913 | """ |
| 1914 | name = name if name else "reduce_variance" |
| 1915 | with ops.name_scope(name): |
| 1916 | means = reduce_mean(input_tensor, axis=axis, keepdims=True) |
| 1917 | squared_deviations = gen_math_ops.square(input_tensor - means) |
| 1918 | return reduce_mean(squared_deviations, axis=axis, keepdims=keepdims) |
| 1919 | |
| 1920 | |
| 1921 | @tf_export("math.reduce_std") |
no test coverage detected