Computes the mean 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)
| 1815 | @tf_export("math.reduce_mean", "reduce_mean", v1=[]) |
| 1816 | @dispatch.add_dispatch_support |
| 1817 | def reduce_mean(input_tensor, axis=None, keepdims=False, name=None): |
| 1818 | """Computes the mean of elements across dimensions of a tensor. |
| 1819 | |
| 1820 | Reduces `input_tensor` along the dimensions given in `axis`. |
| 1821 | Unless `keepdims` is true, the rank of the tensor is reduced by 1 for each |
| 1822 | entry in `axis`. If `keepdims` is true, the reduced dimensions |
| 1823 | are retained with length 1. |
| 1824 | |
| 1825 | If `axis` is None, all dimensions are reduced, and a |
| 1826 | tensor with a single element is returned. |
| 1827 | |
| 1828 | For example: |
| 1829 | |
| 1830 | ```python |
| 1831 | x = tf.constant([[1., 1.], [2., 2.]]) |
| 1832 | tf.reduce_mean(x) # 1.5 |
| 1833 | tf.reduce_mean(x, 0) # [1.5, 1.5] |
| 1834 | tf.reduce_mean(x, 1) # [1., 2.] |
| 1835 | ``` |
| 1836 | |
| 1837 | Args: |
| 1838 | input_tensor: The tensor to reduce. Should have numeric type. |
| 1839 | axis: The dimensions to reduce. If `None` (the default), reduces all |
| 1840 | dimensions. Must be in the range `[-rank(input_tensor), |
| 1841 | rank(input_tensor))`. |
| 1842 | keepdims: If true, retains reduced dimensions with length 1. |
| 1843 | name: A name for the operation (optional). |
| 1844 | |
| 1845 | Returns: |
| 1846 | The reduced tensor. |
| 1847 | |
| 1848 | @compatibility(numpy) |
| 1849 | Equivalent to np.mean |
| 1850 | |
| 1851 | Please note that `np.mean` has a `dtype` parameter that could be used to |
| 1852 | specify the output type. By default this is `dtype=float64`. On the other |
| 1853 | hand, `tf.reduce_mean` has an aggressive type inference from `input_tensor`, |
| 1854 | for example: |
| 1855 | |
| 1856 | ```python |
| 1857 | x = tf.constant([1, 0, 1, 0]) |
| 1858 | tf.reduce_mean(x) # 0 |
| 1859 | y = tf.constant([1., 0., 1., 0.]) |
| 1860 | tf.reduce_mean(y) # 0.5 |
| 1861 | ``` |
| 1862 | |
| 1863 | @end_compatibility |
| 1864 | """ |
| 1865 | keepdims = False if keepdims is None else keepdims |
| 1866 | return _may_reduce_to_scalar( |
| 1867 | keepdims, axis, |
| 1868 | gen_math_ops.mean( |
| 1869 | input_tensor, _ReductionDims(input_tensor, axis), keepdims, |
| 1870 | name=name)) |
| 1871 | |
| 1872 | |
| 1873 | @tf_export("math.reduce_variance") |
no test coverage detected