Variance of a tensor, alongside the specified axis. Arguments: x: A tensor or variable. axis: An integer, the axis to compute the variance. keepdims: A boolean, whether to keep the dimensions or not. If `keepdims` is `False`, the rank of the tensor is reduced
(x, axis=None, keepdims=False)
| 1945 | |
| 1946 | @keras_export('keras.backend.var') |
| 1947 | def var(x, axis=None, keepdims=False): |
| 1948 | """Variance of a tensor, alongside the specified axis. |
| 1949 | |
| 1950 | Arguments: |
| 1951 | x: A tensor or variable. |
| 1952 | axis: An integer, the axis to compute the variance. |
| 1953 | keepdims: A boolean, whether to keep the dimensions or not. |
| 1954 | If `keepdims` is `False`, the rank of the tensor is reduced |
| 1955 | by 1. If `keepdims` is `True`, |
| 1956 | the reduced dimension is retained with length 1. |
| 1957 | |
| 1958 | Returns: |
| 1959 | A tensor with the variance of elements of `x`. |
| 1960 | """ |
| 1961 | if x.dtype.base_dtype == dtypes_module.bool: |
| 1962 | x = math_ops.cast(x, floatx()) |
| 1963 | return math_ops.reduce_variance(x, axis=axis, keepdims=keepdims) |
| 1964 | |
| 1965 | |
| 1966 | @keras_export('keras.backend.std') |