LinearOperator acting like a [batch] of toeplitz matrices.
Inherits From: LinearOperator, Module
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.LinearOperatorToeplitz
This operator acts like a [batch] Toeplitz matrix A with shape [B1,...,Bb, N, N] for some b >= 0. The first b indices index a batch member. For every batch index (i1,...,ib), A[i1,...,ib, : :] is an N x N matrix. This matrix A is not materialized, but for purposes of broadcasting this shape will be relevant.
Toeplitz means that A has constant diagonals. Hence, A can be generated with two vectors. One represents the first column of the matrix, and the other represents the first row.
Below is a 4 x 4 example:
This operator acts on [batch] matrix with compatible shape. x is a batch matrix with compatible shape for matmul and solve if
This LinearOperator is initialized with boolean flags of the form is_X, for X = non_singular, self_adjoint, positive_definite, square. These have the following meaning:
Given A representing this LinearOperator, return A*. Note that calling self.adjoint() and self.H are equivalent.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns TensorShape([B1,...,Bb]), equivalent to A.shape[:-2]
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns N.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns M.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns TensorShape([B1,...,Bb, M, N]), equivalent to A.shape.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns b + 2.
View source
Add matrix represented by this operator to x. Equivalent to A + x.
View source
Returns the adjoint of the current LinearOperator.
Given A representing this LinearOperator, return A*. Note that calling self.adjoint() and self.H are equivalent.
View source
Returns an Op that asserts this operator is non singular.
This operator is considered non-singular if
View source
Returns an Op that asserts this operator is positive definite.
Here, positive definite means that the quadratic form x^H A x has positive real part for all nonzero x. Note that we do not require the operator to be self-adjoint to be positive definite.
View source
Returns an Op that asserts this operator is self-adjoint.
Here we check that this operator is exactly equal to its hermitian transpose.
View source
Shape of batch dimensions of this operator, determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns a Tensor holding [B1,...,Bb].
View source
Returns a Cholesky factor as a LinearOperator.
Given A representing this LinearOperator, if A is positive definite self-adjoint, return L, where A = L L^T, i.e. the cholesky decomposition.
View source
Returns the condition number of this linear operator.
View source
Determinant for every batch member.
View source
Efficiently get the [batch] diagonal part of this operator.
If this operator has shape [B1,...,Bb, M, N], this returns a Tensor diagonal, of shape [B1,...,Bb, min(M, N)], where diagonal[b1,...,bb, i] = self.to_dense()[b1,...,bb, i, i].
View source
Dimension (in the sense of vector spaces) of the domain of this operator.
Determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns N.
View source
Returns the eigenvalues of this linear operator.
If the operator is marked as self-adjoint (via is_self_adjoint) this computation can be more efficient.
View source
Returns the Inverse of this LinearOperator.
Given A representing this LinearOperator, return a LinearOperator representing A^-1.
View source
Log absolute value of determinant for every batch member.
View source
Transform [batch] matrix x with left multiplication: x --> Ax.
View source
Transform [batch] vector x with left multiplication: x --> Ax.
View source
Dimension (in the sense of vector spaces) of the range of this operator.
Determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns M.
View source
Shape of this LinearOperator, determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns a Tensor holding [B1,...,Bb, M, N], equivalent to tf.shape(A).
View source
Solve (exact or approx) R (batch) systems of equations: A X = rhs.
The returned Tensor will be close to an exact solution if A is well conditioned. Otherwise closeness will vary. See class docstring for details.
View source
Solve single equation with best effort: A X = rhs.
The returned Tensor will be close to an exact solution if A is well conditioned. Otherwise closeness will vary. See class docstring for details.
View source
Rank (in the sense of tensors) of matrix corresponding to this operator.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns b + 2.
View source
Return a dense (batch) matrix representing this operator.
View source
Trace of the linear operator, equal to sum of self.diag_part().
If the operator is square, this is also the sum of the eigenvalues.
View source


LinearOperator acting like a [batch] square tridiagonal matrix.
Inherits From: LinearOperator, Module
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.LinearOperatorTridiag
This operator acts like a [batch] square tridiagonal matrix A with shape [B1,...,Bb, N, N] for some b >= 0. The first b indices index a batch member. For every batch index (i1,...,ib), A[i1,...,ib, : :] is an N x M matrix. This matrix A is not materialized, but for purposes of broadcasting this shape will be relevant.
Create a 3 x 3 tridiagonal linear operator.
Scalar Tensor output.
Create a [2, 3] batch of 4 x 4 linear operators.
Create a shape [2, 1, 4, 2] vector. Note that this shape is compatible since the batch dimensions, [2, 1], are broadcast to operator.batch_shape = [2, 3].
This operator acts on [batch] matrix with compatible shape. x is a batch matrix with compatible shape for matmul and solve if
Suppose operator is a LinearOperatorTridiag of shape [N, N], and x.shape = [N, R]. Then
If instead operator and x have shape [B1,...,Bb, N, N] and [B1,...,Bb, N, R], every operation increases in complexity by B1*...*Bb.
This LinearOperator is initialized with boolean flags of the form is_X, for X = non_singular, self_adjoint, positive_definite, square. These have the following meaning:
If diagonals_format=sequence, this is a list of three Tensor's each with shape [B1, ..., Bb, N], b >= 0, N >= 0, representing the superdiagonal, diagonal and subdiagonal in that order. Note the superdiagonal is padded with an element in the last position, and the subdiagonal is padded with an element in the front.
If diagonals_format=matrix this is a [B1, ... Bb, N, N] shaped Tensor representing the full tridiagonal matrix.
If diagonals_format=compact this is a [B1, ... Bb, 3, N] shaped Tensor with the second to last dimension indexing the superdiagonal, diagonal and subdiagonal in that order. Note the superdiagonal is padded with an element in the last position, and the subdiagonal is padded with an element in the front.
In every case, these Tensors are all floating dtype.
Given A representing this LinearOperator, return A*. Note that calling self.adjoint() and self.H are equivalent.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns TensorShape([B1,...,Bb]), equivalent to A.shape[:-2]
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns N.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns M.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns TensorShape([B1,...,Bb, M, N]), equivalent to A.shape.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns b + 2.
View source
Add matrix represented by this operator to x. Equivalent to A + x.
View source
Returns the adjoint of the current LinearOperator.
Given A representing this LinearOperator, return A*. Note that calling self.adjoint() and self.H are equivalent.
View source
Returns an Op that asserts this operator is non singular.
This operator is considered non-singular if
View source
Returns an Op that asserts this operator is positive definite.
Here, positive definite means that the quadratic form x^H A x has positive real part for all nonzero x. Note that we do not require the operator to be self-adjoint to be positive definite.
View source
Returns an Op that asserts this operator is self-adjoint.
Here we check that this operator is exactly equal to its hermitian transpose.
View source
Shape of batch dimensions of this operator, determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns a Tensor holding [B1,...,Bb].
View source
Returns a Cholesky factor as a LinearOperator.
Given A representing this LinearOperator, if A is positive definite self-adjoint, return L, where A = L L^T, i.e. the cholesky decomposition.
View source
Returns the condition number of this linear operator.
View source
Determinant for every batch member.
View source
Efficiently get the [batch] diagonal part of this operator.
If this operator has shape [B1,...,Bb, M, N], this returns a Tensor diagonal, of shape [B1,...,Bb, min(M, N)], where diagonal[b1,...,bb, i] = self.to_dense()[b1,...,bb, i, i].
View source
Dimension (in the sense of vector spaces) of the domain of this operator.
Determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns N.
View source
Returns the eigenvalues of this linear operator.
If the operator is marked as self-adjoint (via is_self_adjoint) this computation can be more efficient.
View source
Returns the Inverse of this LinearOperator.
Given A representing this LinearOperator, return a LinearOperator representing A^-1.
View source
Log absolute value of determinant for every batch member.
View source
Transform [batch] matrix x with left multiplication: x --> Ax.
View source
Transform [batch] vector x with left multiplication: x --> Ax.
View source
Dimension (in the sense of vector spaces) of the range of this operator.
Determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns M.
View source
Shape of this LinearOperator, determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns a Tensor holding [B1,...,Bb, M, N], equivalent to tf.shape(A).
View source
Solve (exact or approx) R (batch) systems of equations: A X = rhs.
The returned Tensor will be close to an exact solution if A is well conditioned. Otherwise closeness will vary. See class docstring for details.
View source
Solve single equation with best effort: A X = rhs.
The returned Tensor will be close to an exact solution if A is well conditioned. Otherwise closeness will vary. See class docstring for details.
View source
Rank (in the sense of tensors) of matrix corresponding to this operator.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns b + 2.
View source
Return a dense (batch) matrix representing this operator.
View source
Trace of the linear operator, equal to sum of self.diag_part().
If the operator is square, this is also the sum of the eigenvalues.
View source


LinearOperator acting like a [batch] zero matrix.
Inherits From: LinearOperator, Module
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.LinearOperatorZeros
This operator acts like a [batch] zero matrix A with shape [B1,...,Bb, N, M] for some b >= 0. The first b indices index a batch member. For every batch index (i1,...,ib), A[i1,...,ib, : :] is an N x M matrix. This matrix A is not materialized, but for purposes of broadcasting this shape will be relevant.
LinearOperatorZeros is initialized with num_rows, and optionally num_columns,batch_shape, anddtypearguments. Ifnum_columnsisNone, then this operator will be initialized as a square matrix. Ifbatch_shapeisNone, this operator efficiently passes through all arguments. Ifbatch_shape` is provided, broadcasting may occur, which will require making copies.
This operator acts on [batch] matrix with compatible shape. x is a batch matrix with compatible shape for matmul and solve if
This LinearOperator is initialized with boolean flags of the form is_X, for X = non_singular, self_adjoint, positive_definite, square. These have the following meaning:
Given A representing this LinearOperator, return A*. Note that calling self.adjoint() and self.H are equivalent.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns TensorShape([B1,...,Bb]), equivalent to A.shape[:-2]
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns N.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns M.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns TensorShape([B1,...,Bb, M, N]), equivalent to A.shape.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns b + 2.
View source
Add matrix represented by this operator to mat. Equiv to I + mat.
View source
Returns the adjoint of the current LinearOperator.
Given A representing this LinearOperator, return A*. Note that calling self.adjoint() and self.H are equivalent.
View source
Returns an Op that asserts this operator is non singular.
This operator is considered non-singular if
View source
Returns an Op that asserts this operator is positive definite.
Here, positive definite means that the quadratic form x^H A x has positive real part for all nonzero x. Note that we do not require the operator to be self-adjoint to be positive definite.
View source
Returns an Op that asserts this operator is self-adjoint.
Here we check that this operator is exactly equal to its hermitian transpose.
View source
Shape of batch dimensions of this operator, determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns a Tensor holding [B1,...,Bb].
View source
Returns a Cholesky factor as a LinearOperator.
Given A representing this LinearOperator, if A is positive definite self-adjoint, return L, where A = L L^T, i.e. the cholesky decomposition.
View source
Returns the condition number of this linear operator.
View source
Determinant for every batch member.
View source
Efficiently get the [batch] diagonal part of this operator.
If this operator has shape [B1,...,Bb, M, N], this returns a Tensor diagonal, of shape [B1,...,Bb, min(M, N)], where diagonal[b1,...,bb, i] = self.to_dense()[b1,...,bb, i, i].
View source
Dimension (in the sense of vector spaces) of the domain of this operator.
Determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns N.
View source
Returns the eigenvalues of this linear operator.
If the operator is marked as self-adjoint (via is_self_adjoint) this computation can be more efficient.
View source
Returns the Inverse of this LinearOperator.
Given A representing this LinearOperator, return a LinearOperator representing A^-1.
View source
Log absolute value of determinant for every batch member.
View source
Transform [batch] matrix x with left multiplication: x --> Ax.
View source
Transform [batch] vector x with left multiplication: x --> Ax.
View source
Dimension (in the sense of vector spaces) of the range of this operator.
Determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns M.
View source
Shape of this LinearOperator, determined at runtime.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns a Tensor holding [B1,...,Bb, M, N], equivalent to tf.shape(A).
View source
Solve (exact or approx) R (batch) systems of equations: A X = rhs.
The returned Tensor will be close to an exact solution if A is well conditioned. Otherwise closeness will vary. See class docstring for details.
View source
Solve single equation with best effort: A X = rhs.
The returned Tensor will be close to an exact solution if A is well conditioned. Otherwise closeness will vary. See class docstring for details.
View source
Rank (in the sense of tensors) of matrix corresponding to this operator.
If this operator acts like the batch matrix A with A.shape = [B1,...,Bb, M, N], then this returns b + 2.
View source
Return a dense (batch) matrix representing this operator.
View source
Trace of the linear operator, equal to sum of self.diag_part().
If the operator is square, this is also the sum of the eigenvalues.
View source


Computes log of the determinant of a hermitian positive definite matrix.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.logdet
Equivalent to numpy.linalg.slogdet, although no sign is returned since only hermitian positive definite matrices are supported.


Computes the matrix logarithm of one or more square matrices:
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.logm
\(log(exp(A)) = A\)
This op is only defined for complex matrices. If A is positive-definite and real, then casting to a complex matrix, taking the logarithm and casting back to a real matrix will give the correct result.
This function computes the matrix logarithm using the Schur-Parlett algorithm. Details of the algorithm can be found in Section 11.6.2 of: Nicholas J. Higham, Functions of Matrices: Theory and Computation, SIAM 2008. ISBN 978-0-898716-46-7.
The input is a tensor of shape [..., M, M] whose inner-most 2 dimensions form square matrices. The output is a tensor of the same shape as the input containing the exponential for all input submatrices [..., :, :].


Solves one or more linear least-squares problems.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.lstsq, tf.compat.v1.matrix_solve_ls
matrix is a tensor of shape [..., M, N] whose inner-most 2 dimensions form M-by-N matrices. Rhs is a tensor of shape [..., M, K] whose inner-most 2 dimensions form M-by-K matrices. The computed output is a Tensor of shape [..., N, K] whose inner-most 2 dimensions form M-by-K matrices that solve the equations matrix[..., :, :] * output[..., :, :] = rhs[..., :, :] in the least squares sense.
Below we will use the following notation for each pair of matrix and right-hand sides in the batch:
matrix=\(A \in \Re^{m \times n}\), rhs=\(B \in \Re^{m \times k}\), output=\(X \in \Re^{n \times k}\), l2_regularizer=\(\lambda\).
If fast is True, then the solution is computed by solving the normal equations using Cholesky decomposition. Specifically, if \(m \ge n\) then \(X = (A^T A + \lambda I)^{-1} A^T B\), which solves the least-squares problem \(X = \mathrm{argmin}_{Z \in \Re^{n \times k} } ||A Z - B||_F^2 + \lambda ||Z||_F^2\). If \(m \lt n\) then output is computed as \(X = A^T (A A^T + \lambda I)^{-1} B\), which (for \(\lambda = 0\)) is the minimum-norm solution to the under-determined linear system, i.e. \(X = \mathrm{argmin}_{Z \in \Re^{n \times k} } ||Z||_F^2 \), subject to \(A Z = B\). Notice that the fast path is only numerically stable when \(A\) is numerically full rank and has a condition number \(\mathrm{cond}(A) \lt \frac{1}{\sqrt{\epsilon_{mach} } }\) or\(\lambda\) is sufficiently large.
If fast is False an algorithm based on the numerically robust complete orthogonal decomposition is used. This computes the minimum-norm least-squares solution, even when \(A\) is rank deficient. This path is typically 6-7 times slower than the fast path. If fast is False then l2_regularizer is ignored.


Computes the LU decomposition of one or more square matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.lu
The input is a tensor of shape [..., M, M] whose inner-most 2 dimensions form square matrices.
The input has to be invertible.
The output consists of two tensors LU and P containing the LU decomposition of all input submatrices [..., :, :]. LU encodes the lower triangular and upper triangular factors.
For each input submatrix of shape [M, M], L is a lower triangular matrix of shape [M, M] with unit diagonal whose entries correspond to the strictly lower triangular part of LU. U is a upper triangular matrix of shape [M, M] whose entries correspond to the upper triangular part, including the diagonal, of LU.
P represents a permutation matrix encoded as a list of indices each between 0 and M-1, inclusive. If P_mat denotes the permutation matrix corresponding to P, then the L, U and P satisfies P_mat * input = L * U.


Computes the inverse given the LU decomposition(s) of one or more matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.lu_matrix_inverse
This op is conceptually identical to,


The reconstruct one or more matrices from their LU decomposition(s).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.lu_reconstruct


Solves systems of linear eqns A X = RHS, given LU factorizations.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.lu_solve


Multiplies matrix a by matrix b, producing a * b.
Main aliases
tf.matmul
See Migration guide for more details.
tf.compat.v1.linalg.matmul, tf.compat.v1.matmul
The inputs must, following any transpositions, be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication dimensions, and any further outer dimensions specify matching batch size.
Both matrices must be of the same type. The supported types are: float16, float32, float64, int32, complex64, complex128.
Either matrix can be transposed or adjointed (conjugated and transposed) on the fly by setting one of the corresponding flag to True. These are False by default.
If one or both of the matrices contain a lot of zeros, a more efficient multiplication algorithm can be used by setting the corresponding a_is_sparse or b_is_sparse flag to True. These are False by default. This optimization is only available for plain matrices (rank-2 tensors) with datatypes bfloat16 or float32.
A simple 2-D tensor matrix multiplication:
A batch matrix multiplication with batch shape [2]:
Since python >= 3.5 the @ operator is supported (see PEP 465). In TensorFlow, it simply calls the tf.matmul() function, so the following lines are equivalent:
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.


Compute the matrix rank of one or more matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.matrix_rank


Transposes last two dimensions of tensor a.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.matrix_transpose, tf.compat.v1.linalg.transpose, tf.compat.v1.matrix_transpose
Note that tf.matmul provides kwargs allowing for transpose of arguments. This is done with minimal cost, and is preferable to using this function. E.g.
In numpy transposes are memory-efficient constant time operations as they simply return a new view of the same data with adjusted strides.
TensorFlow does not support strides, linalg.matrix_transpose returns a new tensor with the items permuted.


Multiplies matrix a by vector b, producing a * b.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.matvec
The matrix a must, following any transpositions, be a tensor of rank >= 2, with shape(a)[-1] == shape(b)[-1], and shape(a)[:-2] able to broadcast with shape(b)[:-1].
Both a and b must be of the same type. The supported types are: float16, float32, float64, int32, complex64, complex128.
Matrix a can be transposed or adjointed (conjugated and transposed) on the fly by setting one of the corresponding flag to True. These are False by default.
If one or both of the inputs contain a lot of zeros, a more efficient multiplication algorithm can be used by setting the corresponding a_is_sparse or b_is_sparse flag to True. These are False by default. This optimization is only available for plain matrices/vectors (rank-2/1 tensors) with datatypes bfloat16 or float32.
output[..., i] = sum_k (a[..., i, k] * b[..., k]), for all indices i.


Normalizes tensor along dimension axis using specified norm.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.normalize
This uses tf.linalg.norm to compute the norm along axis.
This function can compute several different vector norms (the 1-norm, the Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).


Compute the Moore-Penrose pseudo-inverse of one or more matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.pinv
Calculate the generalized inverse of a matrix using its singular-value decomposition (SVD) and including all large singular values.
The pseudo-inverse of a matrix A, is defined as: 'the matrix that 'solves' [the least-squares problem] A @ x = b,' i.e., if x_hat is a solution, then A_pinv is the matrix such that x_hat = A_pinv @ b. It can be shown that if U @ Sigma @ V.T = A is the singular value decomposition of A, then A_pinv = V @ inv(Sigma) U^T. [(Strang, 1980)][1]
This function is analogous to numpy.linalg.pinv. It differs only in default value of rcond. In numpy.linalg.pinv, the default rcond is 1e-15. Here the default is 10. * max(num_rows, num_cols) * np.finfo(dtype).eps.
[1]: G. Strang. 'Linear Algebra and Its Applications, 2nd Ed.' Academic Press, Inc., 1980, pp. 139-142.


Computes the QR decompositions of one or more matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.qr, tf.compat.v1.qr
Computes the QR decomposition of each inner matrix in tensor such that tensor[..., :, :] = q[..., :, :] * r[..., :,:])
Currently, the gradient for the QR decomposition is well-defined only when the first P columns of the inner matrix are linearly independent, where P is the minimum of M and N, the 2 inner-most dimmensions of tensor.


Returns a batched matrix tensor with new batched diagonal values.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.set_diag, tf.compat.v1.matrix_set_diag
Given input and diagonal, this operation returns a tensor with the same shape and values as input, except for the specified diagonals of the innermost matrices. These will be overwritten by the values in diagonal.
input has r+1 dimensions [I, J, ..., L, M, N]. When k is scalar or k[0] == k[1], diagonal has r dimensions [I, J, ..., L, max_diag_len]. Otherwise, it has r+1 dimensions [I, J, ..., L, num_diags, max_diag_len]. num_diags is the number of diagonals, num_diags = k[1] - k[0] + 1. max_diag_len is the longest diagonal in the range [k[0], k[1]], max_diag_len = min(M + min(k[1], 0), N + min(-k[0], 0))
The output is a tensor of rank k+1 with dimensions [I, J, ..., L, M, N]. If k is scalar or k[0] == k[1]:
Otherwise,
where d = n - m, diag_index = k[1] - d, and index_in_diag = n - max(d, 0) + offset.
offset is zero except when the alignment of the diagonal is to the right.
where diag_len(d) = min(cols - max(d, 0), rows + min(d, 0)).


Computes the sign and the log of the absolute value of the determinant of
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.slogdet
one or more square matrices.
The input is a tensor of shape [N, M, M] whose inner-most 2 dimensions form square matrices. The outputs are two tensors containing the signs and absolute values of the log determinants for all N input submatrices [..., :, :] such that determinant = sign*exp(log_abs_determinant). The log_abs_determinant is computed as det(P)*sum(log(diag(LU))) where LU is the LU decomposition of the input and P is the corresponding permutation matrix.


Solves systems of linear equations.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.solve, tf.compat.v1.matrix_solve
Matrix is a tensor of shape [..., M, M] whose inner-most 2 dimensions form square matrices. Rhs is a tensor of shape [..., M, K]. The output is a tensor shape [..., M, K]. If adjoint is False then each output matrix satisfies matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]. If adjoint is True then each output matrix satisfies adjoint(matrix[..., :, :]) * output[..., :, :] = rhs[..., :, :].


Computes the matrix square root of one or more square matrices:
Main aliases
tf.matrix_square_root
See Migration guide for more details.
tf.compat.v1.linalg.sqrtm, tf.compat.v1.matrix_square_root
matmul(sqrtm(A), sqrtm(A)) = A
The input matrix should be invertible. If the input matrix is real, it should have no eigenvalues which are real and negative (pairs of complex conjugate eigenvalues are allowed).
The matrix square root is computed by first reducing the matrix to quasi-triangular form with the real Schur decomposition. The square root of the quasi-triangular matrix is then computed directly. Details of the algorithm can be found in: Nicholas J. Higham, "Computing real square roots of a real matrix", Linear Algebra Appl., 1987.
The input is a tensor of shape [..., M, M] whose inner-most 2 dimensions form square matrices. The output is a tensor of the same shape as the input containing the matrix square root for all input submatrices [..., :, :].


Computes the singular value decompositions of one or more matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.svd, tf.compat.v1.svd
Computes the SVD of each inner matrix in tensor such that tensor[..., :, :] = u[..., :, :] * diag(s[..., :, :]) * transpose(conj(v[..., :, :]))
Mostly equivalent to numpy.linalg.svd, except that


Returns a diagonal tensor with a given diagonal values.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.diag, tf.compat.v1.linalg.tensor_diag
Given a diagonal, this operation returns a tensor with the diagonal and everything else padded with zeros. The diagonal is computed as follows:
Assume diagonal has dimensions [D1,..., Dk], then the output is a tensor of rank 2k with dimensions [D1,..., Dk, D1,..., Dk] where:
output[i1,..., ik, i1,..., ik] = diagonal[i1, ..., ik] and 0 everywhere else.


Returns the diagonal part of the tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.diag_part, tf.compat.v1.linalg.tensor_diag_part
This operation returns a tensor with the diagonal part of the input. The diagonal part is computed as follows:
Assume input has dimensions [D1,..., Dk, D1,..., Dk], then the output is a tensor of rank k with dimensions [D1,..., Dk] where:
diagonal[i1,..., ik] = input[i1, ..., ik, i1,..., ik].
For a rank 2 tensor, linalg.diag_part and linalg.tensor_diag_part produce the same result. For rank 3 and higher, linalg.diag_part extracts the diagonal of each inner-most matrix in the tensor. An example where they differ is given below.


Compute the trace of a tensor x.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.trace, tf.compat.v1.trace
trace(x) returns the sum along the main diagonal of each inner-most matrix in x. If x is of rank k with shape [I, J, K, ..., L, M, N], then output is a tensor of rank k-2 with dimensions [I, J, K, ..., L] where
output[i, j, k, ..., l] = trace(x[i, j, k, ..., l, :, :])


Solve systems of linear equations with upper or lower triangular matrices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.triangular_solve, tf.compat.v1.matrix_triangular_solve
matrix is a tensor of shape [..., M, M] whose inner-most 2 dimensions form square matrices. If lower is True then the strictly upper triangular part of each inner-most matrix is assumed to be zero and not accessed. If lower is False then the strictly lower triangular part of each inner-most matrix is assumed to be zero and not accessed. rhs is a tensor of shape [..., M, N].
The output is a tensor of shape [..., M, N]. If adjoint is True then the innermost matrices in output satisfy matrix equations sum_k matrix[..., i, k] * output[..., k, j] = rhs[..., i, j]. If adjoint is False then the innermost matrices in output satisfy matrix equations sum_k adjoint(matrix[..., i, k]) * output[..., k, j] = rhs[..., i, j].


Multiplies tridiagonal matrix by matrix.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.tridiagonal_matmul
diagonals is representation of 3-diagonal NxN matrix, which depends on diagonals_format.
In matrix format, diagonals must be a tensor of shape [..., M, M], with two inner-most dimensions representing the square tridiagonal matrices. Elements outside of the three diagonals will be ignored.
If sequence format, diagonals is list or tuple of three tensors: [superdiag, maindiag, subdiag], each having shape [..., M]. Last element of superdiag first element of subdiag are ignored.
In compact format the three diagonals are brought together into one tensor of shape [..., 3, M], with last two dimensions containing superdiagonals, diagonals, and subdiagonals, in order. Similarly to sequence format, elements diagonals[..., 0, M-1] and diagonals[..., 2, 0] are ignored.
The sequence format is recommended as the one with the best performance.
rhs is matrix to the right of multiplication. It has shape [..., M, N].


Solves tridiagonal systems of equations.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.linalg.tridiagonal_solve
The input can be supplied in various formats: matrix, sequence and compact, specified by the diagonals_format arg.
In matrix format, diagonals must be a tensor of shape [..., M, M], with two inner-most dimensions representing the square tridiagonal matrices. Elements outside of the three diagonals will be ignored.
In sequence format, diagonals are supplied as a tuple or list of three tensors of shapes [..., N], [..., M], [..., N] representing superdiagonals, diagonals, and subdiagonals, respectively. N can be either M-1 or M; in the latter case, the last element of superdiagonal and the first element of subdiagonal will be ignored.
In compact format the three diagonals are brought together into one tensor of shape [..., 3, M], with last two dimensions containing superdiagonals, diagonals, and subdiagonals, in order. Similarly to sequence format, elements diagonals[..., 0, M-1] and diagonals[..., 2, 0] are ignored.
The compact format is recommended as the one with best performance. In case you need to cast a tensor into a compact format manually, use tf.gather_nd. An example for a tensor of shape [m, m]:
Regardless of the diagonals_format, rhs is a tensor of shape [..., M] or [..., M, K]. The latter allows to simultaneously solve K systems with the same left-hand sides and K different right-hand sides. If transpose_rhs is set to True the expected shape is [..., M] or [..., K, M].
The batch dimensions, denoted as ..., must be the same in diagonals and rhs.
The output is a tensor of the same shape as rhs: either [..., M] or [..., M, K].
The op isn't guaranteed to raise an error if the input matrix is not invertible. tf.debugging.check_numerics can be applied to the output to detect invertibility problems.
On CPU, solution is computed via Gaussian elimination with or without partial pivoting, depending on partial_pivoting parameter. On GPU, Nvidia's cuSPARSE library is used: https://docs.nvidia.com/cuda/cusparse/index.html#gtsv
[1] Nicholas J. Higham (2002). Accuracy and Stability of Numerical Algorithms: Second Edition. SIAM. p. 175. ISBN 978-0-89871-802-7.


Generates evenly-spaced values in an interval along a given axis.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lin_space, tf.compat.v1.linspace
A sequence of num evenly-spaced values are generated beginning at start along a given axis. If num > 1, the values in the sequence increase by stop - start / num - 1, so that the last one is exactly stop. If num <= 0, ValueError is raised.
Matches np.linspace's behaviour except when num == 0.
Start and stop can be tensors of arbitrary size:
Axis is where the values will be generated (the dimension in the returned tensor which corresponds to the axis will be equal to num)


Public API for tf.lite namespace.
experimental module: Public API for tf.lite.experimental namespace.
class Interpreter: Interpreter interface for TensorFlow Lite Models.
class OpsSet: Enum class defining the sets of ops available to generate TFLite models.
class Optimize: Enum defining the optimizations to apply when generating tflite graphs.
class RepresentativeDataset: Representative dataset to evaluate optimizations.
class TFLiteConverter: Converts a TensorFlow model into TensorFlow Lite model.
class TargetSpec: Specification of target device.


Public API for tf.lite.experimental namespace.
load_delegate(...): Returns loaded Delegate object.


Returns loaded Delegate object.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lite.experimental.load_delegate


Interpreter interface for TensorFlow Lite Models.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lite.Interpreter
This makes the TensorFlow Lite interpreter accessible in Python. It is possible to use this interpreter in a multithreaded Python environment, but you must be sure to call functions of a particular instance from only one thread at a time. So if you want to have 4 threads running different inferences simultaneously, create an interpreter for each one as thread-local data. Similarly, if you are calling invoke() in one thread on a single interpreter but you want to use tensor() on another thread once it is done, you must use a synchronization primitive between the threads to ensure invoke has returned before calling tensor().
View source
View source
Gets model input details.
View source
Gets model output details.
View source
Gets the value of the input tensor (get a copy).
If you wish to avoid the copy, use tensor(). This function cannot be used to read intermediate results.
View source
Gets tensor details for every tensor with valid tensor details.
Tensors where required information about the tensor is not found are not added to the list. This includes temporary tensors without a name.
View source
Invoke the interpreter.
Be sure to set the input sizes, allocate tensors and fill values before calling this. Also, note that this function releases the GIL so heavy computation can be done in the background while the Python interpreter continues. No other function on this object should be called while the invoke() call has not finished.
View source
View source
Resizes an input tensor.
View source
Sets the value of the input tensor.
Note this copies data in value.
If you want to avoid copying, you can use the tensor() function to get a numpy buffer pointing to the input buffer in the tflite interpreter.
View source
Returns function that gives a numpy view of the current tensor buffer.
This allows reading and writing to this tensors w/o copies. This more closely mirrors the C++ Interpreter class interface's tensor() member, hence the name. Be careful to not hold these output references through calls to allocate_tensors() and invoke(). This function cannot be used to read intermediate results.
Notice how this function avoids making a numpy array directly. This is because it is important to not hold actual numpy views to the data longer than necessary. If you do, then the interpreter can no longer be invoked, because it is possible the interpreter would resize and invalidate the referenced tensors. The NumPy API doesn't allow any mutability of the the underlying buffers.


Enum class defining the sets of ops available to generate TFLite models.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lite.OpsSet


Enum defining the optimizations to apply when generating tflite graphs.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lite.Optimize
Some optimizations may come at the cost of accuracy.
DEFAULT Default optimization strategy.
OPTIMIZE_FOR_SIZE Deprecated. Does the same as DEFAULT.
OPTIMIZE_FOR_LATENCY Deprecated. Does the same as DEFAULT.


Representative dataset to evaluate optimizations.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lite.RepresentativeDataset
A representative dataset that can be used to evaluate optimizations by the converter. E.g. converter can use these examples to estimate (min, max) ranges by calibrating the model on inputs. This can allow converter to quantize a converted floating point model.


Specification of target device.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lite.TargetSpec
Details about target device. Converter optimizes the generated model for specific device.


Converts a TensorFlow model into TensorFlow Lite model.
View source
Converts a TensorFlow GraphDef based on instance variables.
View source
Creates a TFLiteConverter object from ConcreteFunctions.
View source
Creates a TFLiteConverter object from a Keras model.
View source
Creates a TFLiteConverter object from a SavedModel directory.


Loads a TensorFlow plugin.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.load_library
"library_location" can be a path to a specific shared object, or a folder. If it is a folder, all shared objects that are named "libtfkernel*" will be loaded. When the library is loaded, kernels registered in the library via the REGISTER_* macros are made available in the TensorFlow process.


Loads a TensorFlow plugin, containing custom ops and kernels.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.load_op_library
Pass "library_filename" to a platform-specific mechanism for dynamically loading a library. The rules for determining the exact location of the library are platform-specific and are not documented here. When the library is loaded, ops and kernels registered in the library via the REGISTER_* macros are made available in the TensorFlow process. Note that ops with the same name as an existing op are rejected and not registered with the process.


Public API for tf.lookup namespace.
experimental module: Public API for tf.lookup.experimental namespace.
class KeyValueTensorInitializer: Table initializers given keys and values tensors.
class StaticHashTable: A generic hash table that is immutable once initialized.
class StaticVocabularyTable: String to Id table that assigns out-of-vocabulary keys to hash buckets.
class TextFileIndex: The key and value content to get from each line.
class TextFileInitializer: Table initializers from a text file.


Public API for tf.lookup.experimental namespace.
class DatasetInitializer: Creates a table initializer from a tf.data.Dataset.
class DenseHashTable: A generic mutable hash table implementation using tensors as backing store.


Creates a table initializer from a tf.data.Dataset.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lookup.experimental.DatasetInitializer
Raises: ValueError if dataset doesn't conform to specifications.
View source
Returns the table initialization op.


A generic mutable hash table implementation using tensors as backing store.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lookup.experimental.DenseHashTable
Data can be inserted by calling the insert method and removed by calling the remove method. It does not support initialization via the init method.
It uses "open addressing" with quadratic reprobing to resolve collisions. Compared to MutableHashTable the insert, remove and lookup operations in a DenseHashTable are typically faster, but memory usage can be higher. However, DenseHashTable does not require additional memory for temporary tensors created during checkpointing and restore operations.
View source
Removes keys and its associated values from the table.
If a key is not present in the table, it is silently ignored.
View source
Returns tensors of all keys and values in the table.
View source
Associates keys with values.
View source
Associates keys with values.
View source
Looks up keys in a table, outputs the corresponding values.
The default_value is used for keys not present in the table.
View source
Removes keys and its associated values from the table.
If a key is not present in the table, it is silently ignored.
View source
Compute the number of elements in this table.
View source
Looks up keys in a table, outputs the corresponding values.


Table initializers given keys and values tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lookup.KeyValueTensorInitializer
View source
Initializes the given table with keys and values tensors.


A generic hash table that is immutable once initialized.
Or for more pythonic code:
The result of a lookup operation has the same shape as the argument:
View source
Returns tensors of all keys and values in the table.
View source
Looks up keys in a table, outputs the corresponding values.
The default_value is used for keys not present in the table.
View source
Compute the number of elements in this table.
View source
Looks up keys in a table, outputs the corresponding values.


String to Id table that assigns out-of-vocabulary keys to hash buckets.
For example, if an instance of StaticVocabularyTable is initialized with a string-to-id initializer that maps:
The Vocabulary object will performs the following mapping:
If initializer is None, only out-of-vocabulary buckets are used.
The hash function used for generating out-of-vocabulary buckets ID is Fingerprint64.
View source
Looks up keys in the table, outputs the corresponding values.
It assigns out-of-vocabulary keys to buckets based in their hashes.
View source
Compute the number of elements in this table.
View source
Looks up keys in a table, outputs the corresponding values.


The key and value content to get from each line.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lookup.TextFileIndex
This class defines the key and value used for tf.lookup.TextFileInitializer.
The key and value content to get from each line is specified either by the following, or a value >=0.
A value >=0 means use the index (starting at zero) of the split line based on delimiter.


Table initializers from a text file.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lookup.TextFileInitializer
This initializer assigns one entry in the table for each line in the file.
The key and value type of the table to initialize is given by key_dtype and value_dtype.
The key and value content to get from each line is specified by the key_index and value_index.
For example if we have a file with the following content:
The following snippet initializes a table with the first column as keys and second column as values:
Similarly to initialize the whole line as keys and the line number as values.
View source
Initializes the table from a text file.


Create a numpy ndarray from a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.make_ndarray
Create a numpy ndarray with the same shape and data as the tensor.


Create a TensorProto.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.make_tensor_proto
In TensorFlow 2.0, representing tensors as protos should no longer be a common workflow. That said, this utility function is still useful for generating TF Serving request protos:
make_tensor_proto accepts "values" of a python scalar, a python list, a numpy ndarray, or a numpy scalar.
If "values" is a python scalar or a python list, make_tensor_proto first convert it to numpy ndarray. If dtype is None, the conversion tries its best to infer the right numpy data type. Otherwise, the resulting numpy array has a compatible data type with the given dtype.
In either case above, the numpy ndarray (either the caller provided or the auto-converted) must have the compatible type with dtype.
make_tensor_proto then converts the numpy array to a tensor proto.
If "shape" is None, the resulting tensor proto represents the numpy array precisely.
Otherwise, "shape" specifies the tensor's shape and the numpy array can not have more elements than what "shape" specifies.
If values is a TensorProto, it is immediately returned; dtype and shape are ignored.


Transforms elems by applying fn to each element unstacked on axis 0. (deprecated arguments)
See also tf.scan.
map_fn unstacks elems on axis 0 to obtain a sequence of elements; calls fn to transform each element; and then stacks the transformed values back together.
If elems is a single tensor and fn's signature is tf.Tensor->tf.Tensor, then map_fn(fn, elems) is equivalent to tf.stack([fn(elem) for elem in tf.unstack(elems)]). E.g.:
map_fn(fn, elems).shape = [elems.shape[0]] + fn(elems[0]).shape.
map_fn also supports functions with multi-arity inputs and outputs:
If elems is a tuple (or nested structure) of tensors, then those tensors must all have the same outer-dimension size (num_elems); and fn is used to transform each tuple (or structure) of corresponding slices from elems. E.g., if elems is a tuple (t1, t2, t3), then fn is used to transform each tuple of slices (t1[i], t2[i], t3[i]) (where 0 <= i < num_elems).
If fn returns a tuple (or nested structure) of tensors, then the result is formed by stacking corresponding elements from those structures.
If fn's input and output signatures are different, then the output signature must be specified using fn_output_signature. (The input and output signatures are differ if their structures, dtypes, or tensor types do not match). E.g.:
fn_output_signature can be specified using any of the following:
map_fn supports tf.RaggedTensor inputs and outputs. In particular:
If elems is a RaggedTensor, then fn will be called with each row of that ragged tensor.
If the result of map_fn should be a RaggedTensor, then use a tf.RaggedTensorSpec to specify fn_output_signature.
E.g.:
map_fn supports tf.sparse.SparseTensor inputs and outputs. In particular:
If elems is a SparseTensor, then fn will be called with each row of that sparse tensor. In particular, the value passed to fn will be a tf.sparse.SparseTensor with one fewer dimension than elems.
If the result of map_fn should be a SparseTensor, then use a tf.SparseTensorSpec to specify fn_output_signature. The individual SparseTensors returned by fn will be stacked into a single SparseTensor with one more dimension.
If the function is expressible as TensorFlow ops, use:
Otherwise, use:
map_fn will apply the operations used by fn to each element of elems, resulting in O(elems.shape[0]) total operations. This is somewhat mitigated by the fact that map_fn can process elements in parallel. However, a transform expressed using map_fn is still typically less efficient than an equivalent transform expressed using vectorized operations.
map_fn should typically only be used if one of the following is true:
E.g., the example given above that maps fn=lambda t: tf.range(t, t + 3) across elems could be rewritten more efficiently using vectorized ops:
In some cases, tf.vectorized_map can be used to automatically convert a function to a vectorized eqivalent.
When executing eagerly, map_fn does not execute in parallel even if parallel_iterations is set to a value > 1. You can still get the performance benefits of running a function in parallel by using the tf.function decorator:


Math Operations.
TensorFlow provides a variety of math functions including:
See: tf.linalg for matrix and tensor functions.
TensorFlow provides several operations that you can use to perform common math computations on tensor segments. Here a segmentation is a partitioning of a tensor along the first dimension, i.e. it defines a mapping from the first dimension onto segment_ids. The segment_ids tensor should be the size of the first dimension, d0, with consecutive IDs in the range 0 to k, where k<d0. In particular, a segmentation of a matrix tensor is a mapping of rows to segments.
The standard segment_* functions assert that the segment indices are sorted. If you have unsorted indices use the equivalent unsorted_segment_ function. These functions take an additional argument num_segments so that the output tensor can be efficiently allocated.
special module: Public API for tf.math.special namespace.
abs(...): Computes the absolute value of a tensor.
accumulate_n(...): Returns the element-wise sum of a list of tensors.
acos(...): Computes acos of x element-wise.
acosh(...): Computes inverse hyperbolic cosine of x element-wise.
add(...): Returns x + y element-wise.
add_n(...): Adds all input tensors element-wise.
angle(...): Returns the element-wise argument of a complex (or real) tensor.
argmax(...): Returns the index with the largest value across axes of a tensor.
argmin(...): Returns the index with the smallest value across axes of a tensor.
asin(...): Computes the trignometric inverse sine of x element-wise.
asinh(...): Computes inverse hyperbolic sine of x element-wise.
atan(...): Computes the trignometric inverse tangent of x element-wise.
atan2(...): Computes arctangent of y/x element-wise, respecting signs of the arguments.
atanh(...): Computes inverse hyperbolic tangent of x element-wise.
bessel_i0(...): Computes the Bessel i0 function of x element-wise.
bessel_i0e(...): Computes the Bessel i0e function of x element-wise.
bessel_i1(...): Computes the Bessel i1 function of x element-wise.
bessel_i1e(...): Computes the Bessel i1e function of x element-wise.
betainc(...): Compute the regularized incomplete beta integral \(I_x(a, b)\).
bincount(...): Counts the number of occurrences of each value in an integer array.
ceil(...): Return the ceiling of the input, element-wise.
confusion_matrix(...): Computes the confusion matrix from predictions and labels.
conj(...): Returns the complex conjugate of a complex number.
cos(...): Computes cos of x element-wise.
cosh(...): Computes hyperbolic cosine of x element-wise.
count_nonzero(...): Computes number of nonzero elements across dimensions of a tensor.
cumprod(...): Compute the cumulative product of the tensor x along axis.
cumsum(...): Compute the cumulative sum of the tensor x along axis.
cumulative_logsumexp(...): Compute the cumulative log-sum-exp of the tensor x along axis.
digamma(...): Computes Psi, the derivative of Lgamma (the log of the absolute value of
divide(...): Computes Python style division of x by y.
divide_no_nan(...): Computes a safe divide which returns 0 if the y is zero.
equal(...): Returns the truth value of (x == y) element-wise.
erf(...): Computes the Gauss error function of x element-wise.
erfc(...): Computes the complementary error function of x element-wise.
erfcinv(...): Computes the inverse of complementary error function.
erfinv(...): Compute inverse error function.
exp(...): Computes exponential of x element-wise. \(y = e^x\).
expm1(...): Computes exp(x) - 1 element-wise.
floor(...): Returns element-wise largest integer not greater than x.
floordiv(...): Divides x / y elementwise, rounding toward the most negative integer.
floormod(...): Returns element-wise remainder of division. When x < 0 xor y < 0 is
greater(...): Returns the truth value of (x > y) element-wise.
greater_equal(...): Returns the truth value of (x >= y) element-wise.
igamma(...): Compute the lower regularized incomplete Gamma function P(a, x).
igammac(...): Compute the upper regularized incomplete Gamma function Q(a, x).
imag(...): Returns the imaginary part of a complex (or real) tensor.
in_top_k(...): Says whether the targets are in the top K predictions.
invert_permutation(...): Computes the inverse permutation of a tensor.
is_finite(...): Returns which elements of x are finite.
is_inf(...): Returns which elements of x are Inf.
is_nan(...): Returns which elements of x are NaN.
is_non_decreasing(...): Returns True if x is non-decreasing.
is_strictly_increasing(...): Returns True if x is strictly increasing.
l2_normalize(...): Normalizes along dimension axis using an L2 norm.
lbeta(...): Computes \(ln(|Beta(x)|)\), reducing along the last dimension.
less(...): Returns the truth value of (x < y) element-wise.
less_equal(...): Returns the truth value of (x <= y) element-wise.
lgamma(...): Computes the log of the absolute value of Gamma(x) element-wise.
log(...): Computes natural logarithm of x element-wise.
log1p(...): Computes natural logarithm of (1 + x) element-wise.
log_sigmoid(...): Computes log sigmoid of x element-wise.
log_softmax(...): Computes log softmax activations.
logical_and(...): Logical AND function.
logical_not(...): Returns the truth value of NOT x element-wise.
logical_or(...): Returns the truth value of x OR y element-wise.
logical_xor(...): Logical XOR function.
maximum(...): Returns the max of x and y (i.e. x > y ? x : y) element-wise.
minimum(...): Returns the min of x and y (i.e. x < y ? x : y) element-wise.
mod(...): Returns element-wise remainder of division. When x < 0 xor y < 0 is
multiply(...): Returns an element-wise x * y.
multiply_no_nan(...): Computes the product of x and y and returns 0 if the y is zero, even if x is NaN or infinite.
ndtri(...): Compute quantile of Standard Normal.
negative(...): Computes numerical negative value element-wise.
nextafter(...): Returns the next representable value of x1 in the direction of x2, element-wise.
not_equal(...): Returns the truth value of (x != y) element-wise.
polygamma(...): Compute the polygamma function \(\psi^{(n)}(x)\).
polyval(...): Computes the elementwise value of a polynomial.
pow(...): Computes the power of one value to another.
real(...): Returns the real part of a complex (or real) tensor.
reciprocal(...): Computes the reciprocal of x element-wise.
reciprocal_no_nan(...): Performs a safe reciprocal operation, element wise.
reduce_all(...): Computes the "logical and" of elements across dimensions of a tensor.
reduce_any(...): Computes the "logical or" of elements across dimensions of a tensor.
reduce_euclidean_norm(...): Computes the Euclidean norm of elements across dimensions of a tensor.
reduce_logsumexp(...): Computes log(sum(exp(elements across dimensions of a tensor))).
reduce_max(...): Computes the maximum of elements across dimensions of a tensor.
reduce_mean(...): Computes the mean of elements across dimensions of a tensor.
reduce_min(...): Computes the minimum of elements across dimensions of a tensor.
reduce_prod(...): Computes the product of elements across dimensions of a tensor.
reduce_std(...): Computes the standard deviation of elements across dimensions of a tensor.
reduce_sum(...): Computes the sum of elements across dimensions of a tensor.
reduce_variance(...): Computes the variance of elements across dimensions of a tensor.
rint(...): Returns element-wise integer closest to x.
round(...): Rounds the values of a tensor to the nearest integer, element-wise.
rsqrt(...): Computes reciprocal of square root of x element-wise.
scalar_mul(...): Multiplies a scalar times a Tensor or IndexedSlices object.
segment_max(...): Computes the maximum along segments of a tensor.
segment_mean(...): Computes the mean along segments of a tensor.
segment_min(...): Computes the minimum along segments of a tensor.
segment_prod(...): Computes the product along segments of a tensor.
segment_sum(...): Computes the sum along segments of a tensor.
sigmoid(...): Computes sigmoid of x element-wise.
sign(...): Returns an element-wise indication of the sign of a number.
sin(...): Computes sine of x element-wise.
sinh(...): Computes hyperbolic sine of x element-wise.
sobol_sample(...): Generates points from the Sobol sequence.
softmax(...): Computes softmax activations.
softplus(...): Computes softplus: log(exp(features) + 1).
softsign(...): Computes softsign: features / (abs(features) + 1).
sqrt(...): Computes element-wise square root of the input tensor.
square(...): Computes square of x element-wise.
squared_difference(...): Returns conj(x - y)(x - y) element-wise.
subtract(...): Returns x - y element-wise.
tan(...): Computes tan of x element-wise.
tanh(...): Computes hyperbolic tangent of x element-wise.
top_k(...): Finds values and indices of the k largest entries for the last dimension.
truediv(...): Divides x / y elementwise (using Python 3 division operator semantics).
unsorted_segment_max(...): Computes the maximum along segments of a tensor.
unsorted_segment_mean(...): Computes the mean along segments of a tensor.
unsorted_segment_min(...): Computes the minimum along segments of a tensor.
unsorted_segment_prod(...): Computes the product along segments of a tensor.
unsorted_segment_sqrt_n(...): Computes the sum along segments of a tensor divided by the sqrt(N).
unsorted_segment_sum(...): Computes the sum along segments of a tensor.
xdivy(...): Returns 0 if x == 0, and x / y otherwise, elementwise.
xlog1py(...): Compute x * log1p(y).
xlogy(...): Returns 0 if x == 0, and x * log(y) otherwise, elementwise.
zero_fraction(...): Returns the fraction of zeros in value.
zeta(...): Compute the Hurwitz zeta function \(\zeta(x, q)\).


Computes the absolute value of a tensor.
Main aliases
tf.abs
See Migration guide for more details.
tf.compat.v1.abs, tf.compat.v1.math.abs
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Given a tensor x of complex numbers, this operation returns a tensor of type float32 or float64 that is the absolute value of each element in x. For a complex number \(a + bj\), its absolute value is computed as \(\sqrt{a^2 + b^2}\).
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)


Returns the element-wise sum of a list of tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.accumulate_n, tf.compat.v1.math.accumulate_n
Optionally, pass shape and tensor_dtype for shape and type checking, otherwise, these are inferred.
accumulate_n performs the same operation as tf.math.add_n.


Computes acos of x element-wise.
Main aliases
tf.acos
See Migration guide for more details.
tf.compat.v1.acos, tf.compat.v1.math.acos
Provided an input tensor, the tf.math.acos operation returns the inverse cosine of each element of the tensor. If y = tf.math.cos(x) then, x = tf.math.acos(y).
Input range is [-1, 1] and the output has a range of [0, pi].


Computes inverse hyperbolic cosine of x element-wise.
Main aliases
tf.acosh
See Migration guide for more details.
tf.compat.v1.acosh, tf.compat.v1.math.acosh
Given an input tensor, the function computes inverse hyperbolic cosine of every element. Input range is [1, inf]. It returns nan if the input lies outside the range.


Returns x + y element-wise.
Main aliases
tf.add
See Migration guide for more details.
tf.compat.v1.add, tf.compat.v1.math.add
Given two input tensors, the tf.add operation computes the sum for every element in the tensor.
Both input and output have a range (-inf, inf).


Adds all input tensors element-wise.
Main aliases
tf.add_n
See Migration guide for more details.
tf.compat.v1.add_n, tf.compat.v1.math.add_n
tf.math.add_n performs the same operation as tf.math.accumulate_n, but it waits for all of its inputs to be ready before beginning to sum. This buffering can result in higher memory consumption when inputs are ready at different times, since the minimum temporary storage required is proportional to the input size rather than the output size.
This op does not broadcast its inputs. If you need broadcasting, use tf.math.add (or the + operator) instead.


Returns the element-wise argument of a complex (or real) tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.angle, tf.compat.v1.math.angle
Given a tensor input, this operation returns a tensor of type float that is the argument of each element in input considered as a complex number.
The elements in input are considered to be complex numbers of the form \(a + bj\), where a is the real part and b is the imaginary part. If input is real then b is zero by definition.
The argument returned by this function is of the form \(atan2(b, a)\). If input is real, a tensor of all zeros is returned.


Returns the index with the largest value across axes of a tensor.
Main aliases
tf.argmax
In case of identity returns the smallest index.


Returns the index with the smallest value across axes of a tensor.
Main aliases
tf.argmin
Returns the smallest index in case of ties.


Computes the trignometric inverse sine of x element-wise.
Main aliases
tf.asin
See Migration guide for more details.
tf.compat.v1.asin, tf.compat.v1.math.asin
The tf.math.asin operation returns the inverse of tf.math.sin, such that if y = tf.math.sin(x) then, x = tf.math.asin(y).


Computes inverse hyperbolic sine of x element-wise.
Main aliases
tf.asinh
See Migration guide for more details.
tf.compat.v1.asinh, tf.compat.v1.math.asinh
Given an input tensor, this function computes inverse hyperbolic sine for every element in the tensor. Both input and output has a range of [-inf, inf].


Computes the trignometric inverse tangent of x element-wise.
Main aliases
tf.atan
See Migration guide for more details.
tf.compat.v1.atan, tf.compat.v1.math.atan
The tf.math.atan operation returns the inverse of tf.math.tan, such that if y = tf.math.tan(x) then, x = tf.math.atan(y).


Computes arctangent of y/x element-wise, respecting signs of the arguments.
Main aliases
tf.atan2
See Migration guide for more details.
tf.compat.v1.atan2, tf.compat.v1.math.atan2
This is the angle ( \theta \in [-\pi, \pi] ) such that [ x = r \cos(\theta) ] and [ y = r \sin(\theta) ] where (r = \sqrt(x^2 + y^2) ).


Computes inverse hyperbolic tangent of x element-wise.
Main aliases
tf.atanh
See Migration guide for more details.
tf.compat.v1.atanh, tf.compat.v1.math.atanh
Given an input tensor, this function computes inverse hyperbolic tangent for every element in the tensor. Input range is [-1,1] and output range is [-inf, inf]. If input is -1, output will be -inf and if the input is 1, output will be inf. Values outside the range will have nan as output.


Computes the Bessel i0 function of x element-wise.
Main aliases
tf.math.special.bessel_i0
See Migration guide for more details.
tf.compat.v1.math.bessel_i0, tf.compat.v1.math.special.bessel_i0
Modified Bessel function of order 0.
It is preferable to use the numerically stabler function i0e(x) instead.
Equivalent to scipy.special.i0


Computes the Bessel i0e function of x element-wise.
Main aliases
tf.math.special.bessel_i0e
See Migration guide for more details.
tf.compat.v1.math.bessel_i0e, tf.compat.v1.math.special.bessel_i0e
Modified Bessel function of order 0.
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.bessel_i0e(x.values, ...), x.dense_shape)
Equivalent to scipy.special.i0e


Computes the Bessel i1 function of x element-wise.
Main aliases
tf.math.special.bessel_i1
See Migration guide for more details.
tf.compat.v1.math.bessel_i1, tf.compat.v1.math.special.bessel_i1
Modified Bessel function of order 1.
It is preferable to use the numerically stabler function i1e(x) instead.
Equivalent to scipy.special.i1


Computes the Bessel i1e function of x element-wise.
Main aliases
tf.math.special.bessel_i1e
See Migration guide for more details.
tf.compat.v1.math.bessel_i1e, tf.compat.v1.math.special.bessel_i1e
Modified Bessel function of order 1.
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.bessel_i1e(x.values, ...), x.dense_shape)
Equivalent to scipy.special.i1e


Compute the regularized incomplete beta integral \(I_x(a, b)\).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.betainc, tf.compat.v1.math.betainc
The regularized incomplete beta integral is defined as:
\(I_x(a, b) = \frac{B(x; a, b)}{B(a, b)}\)
where
\(B(x; a, b) = \int_0^x t^{a-1} (1 - t)^{b-1} dt\)
is the incomplete beta function and \(B(a, b)\) is the complete beta function.


Counts the number of occurrences of each value in an integer array.
If minlength and maxlength are not given, returns a vector with length tf.reduce_max(arr) + 1 if arr is non-empty, and length 0 otherwise. If weights are non-None, then index i of the output stores the sum of the value in weights at each index where the corresponding value in arr is i.
Vector length = Maximum element in vector values is 5. Adding 1, which is 6 will be the vector length.
Each bin value in the output indicates number of occurrences of the particular index. Here, index 1 in output has a value 2. This indicates value 1 occurs two times in values.
Bin will be incremented by the corresponding weight instead of 1. Here, index 1 in output has a value 6. This is the summation of weights corresponding to the value in values.
Bin-counting on a certain axis
This example takes a 2 dimensional input and returns a Tensor with bincounting on each sample.
Bin-counting with binary_output
This example gives binary output instead of counting the occurrence.


Return the ceiling of the input, element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.ceil, tf.compat.v1.math.ceil
Equivalent to np.ceil


Computes the confusion matrix from predictions and labels.
The matrix columns represent the prediction labels and the rows represent the real labels. The confusion matrix is always a 2-D array of shape [n, n], where n is the number of valid labels for a given classification task. Both prediction and labels must be 1-D arrays of the same shape in order for this function to work.
If num_classes is None, then num_classes will be set to one plus the maximum value in either predictions or labels. Class labels are expected to start at 0. For example, if num_classes is 3, then the possible labels would be [0, 1, 2].
If weights is not None, then each prediction contributes its corresponding weight to the total value of the confusion matrix cell.
Note that the possible labels are assumed to be [0, 1, 2, 3, 4], resulting in a 5x5 confusion matrix.


Returns the complex conjugate of a complex number.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.conj, tf.compat.v1.math.conj
Given a tensor x of complex numbers, this operation returns a tensor of complex numbers that are the complex conjugate of each element in x. The complex numbers in x must be of the form \(a + bj\), where a is the real part and b is the imaginary part.
The complex conjugate returned by this operation is of the form \(a - bj\).
If x is real, it is returned unchanged.
Equivalent to numpy.conj.


Computes cos of x element-wise.
Main aliases
tf.cos
See Migration guide for more details.
tf.compat.v1.cos, tf.compat.v1.math.cos
Given an input tensor, this function computes cosine of every element in the tensor. Input range is (-inf, inf) and output range is [-1,1]. If input lies outside the boundary, nan is returned.


Computes hyperbolic cosine of x element-wise.
Main aliases
tf.cosh
See Migration guide for more details.
tf.compat.v1.cosh, tf.compat.v1.math.cosh
Given an input tensor, this function computes hyperbolic cosine of every element in the tensor. Input range is [-inf, inf] and output range is [1, inf].


Computes number of nonzero elements across dimensions of a tensor.
Reduces input 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.
If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.


Compute the cumulative product of the tensor x along axis.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.cumprod, tf.compat.v1.math.cumprod
By default, this op performs an inclusive cumprod, which means that the first element of the input is identical to the first element of the output:
By setting the exclusive kwarg to True, an exclusive cumprod is performed instead:
By setting the reverse kwarg to True, the cumprod is performed in the opposite direction:
This is more efficient than using separate tf.reverse ops. The reverse and exclusive kwargs can also be combined:


Compute the cumulative sum of the tensor x along axis.
Main aliases
tf.cumsum
See Migration guide for more details.
tf.compat.v1.cumsum, tf.compat.v1.math.cumsum
By default, this op performs an inclusive cumsum, which means that the first element of the input is identical to the first element of the output: For example:
By setting the exclusive kwarg to True, an exclusive cumsum is performed instead:
By setting the reverse kwarg to True, the cumsum is performed in the opposite direction:
This is more efficient than using separate tf.reverse ops. The reverse and exclusive kwargs can also be combined:


Compute the cumulative log-sum-exp of the tensor x along axis.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.cumulative_logsumexp
By default, this op performs an inclusive cumulative log-sum-exp, which means that the first element of the input is identical to the first element of the output.
This operation is significantly more numerically stable than the equivalent tensorflow operation tf.math.log(tf.math.cumsum(tf.math.exp(x))), although computes the same result given infinite numerical precision. However, note that in some cases, it may be less stable than tf.math.reduce_logsumexp for a given element, as it applies the "log-sum-exp trick" in a different way.
More precisely, where tf.math.reduce_logsumexp uses the following trick:
it cannot be directly used here as there is no fast way of applying it to each prefix x[:i]. Instead, this function implements a prefix scan using pairwise log-add-exp, which is a commutative and associative (up to floating point precision) operator:
However, reducing using the above operator leads to a different computation tree (logs are taken repeatedly instead of only at the end), and the maximum is only computed pairwise instead of over the entire prefix. In general, this leads to a different and slightly less precise computation.


Computes Psi, the derivative of Lgamma (the log of the absolute value of
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.digamma, tf.compat.v1.math.digamma
Gamma(x)), element-wise.


Computes Python style division of x by y.
Main aliases
tf.divide
See Migration guide for more details.
tf.compat.v1.divide, tf.compat.v1.math.divide


Computes a safe divide which returns 0 if the y is zero.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.div_no_nan, tf.compat.v1.math.divide_no_nan


Returns the truth value of (x == y) element-wise.
Main aliases
tf.equal
See Migration guide for more details.
tf.compat.v1.equal, tf.compat.v1.math.equal
Performs a broadcast with the arguments and then an element-wise equality comparison, returning a Tensor of boolean values.


Computes the Gauss error function of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.erf, tf.compat.v1.math.erf
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.erf(x.values, ...), x.dense_shape)


Computes the complementary error function of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.erfc, tf.compat.v1.math.erfc


Computes the inverse of complementary error function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.erfcinv
Given x, compute the inverse complementary error function of x. This function is the inverse of tf.math.erfc, and is defined on [0, 2].
Equivalent to scipy.special.erfcinv


Compute inverse error function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.erfinv
Given x, compute the inverse error function of x. This function is the inverse of tf.math.erf.


Computes exponential of x element-wise. \(y = e^x\).
Main aliases
tf.exp
See Migration guide for more details.
tf.compat.v1.exp, tf.compat.v1.math.exp
This function computes the exponential of the input tensor element-wise. i.e. math.exp(x) or \(e^x\), where x is the input tensor. \(e\) denotes Euler's number and is approximately equal to 2.718281. Output is positive for any real input.
For complex numbers, the exponential value is calculated as
For 1+1j the value would be computed as:
Equivalent to np.exp


Computes exp(x) - 1 element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.expm1, tf.compat.v1.math.expm1
i.e. exp(x) - 1 or e^(x) - 1, where x is the input tensor. e denotes Euler's number and is approximately equal to 2.718281.


Returns element-wise largest integer not greater than x.
Main aliases
tf.floor
See Migration guide for more details.
tf.compat.v1.floor, tf.compat.v1.math.floor
Both input range is (-inf, inf) and the ouput range consists of all integer values.


Divides x / y elementwise, rounding toward the most negative integer.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.floordiv, tf.compat.v1.math.floordiv
The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.
x and y must have the same type, and the result will have the same type as well.


Returns element-wise remainder of division. When x < 0 xor y < 0 is
Main aliases
tf.math.mod
See Migration guide for more details.
tf.compat.v1.floormod, tf.compat.v1.math.floormod, tf.compat.v1.math.mod, tf.compat.v1.mod
true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.


Returns the truth value of (x > y) element-wise.
Main aliases
tf.greater
See Migration guide for more details.
tf.compat.v1.greater, tf.compat.v1.math.greater


Returns the truth value of (x >= y) element-wise.
Main aliases
tf.greater_equal
See Migration guide for more details.
tf.compat.v1.greater_equal, tf.compat.v1.math.greater_equal


Compute the lower regularized incomplete Gamma function P(a, x).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.igamma, tf.compat.v1.math.igamma
The lower regularized incomplete Gamma function is defined as:
\(P(a, x) = gamma(a, x) / Gamma(a) = 1 - Q(a, x)\)
where
\(gamma(a, x) = \\int_{0}^{x} t^{a-1} exp(-t) dt\)
is the lower incomplete Gamma function.
Note, above Q(a, x) (Igammac) is the upper regularized complete Gamma function.


Compute the upper regularized incomplete Gamma function Q(a, x).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.igammac, tf.compat.v1.math.igammac
The upper regularized incomplete Gamma function is defined as:
\(Q(a, x) = Gamma(a, x) / Gamma(a) = 1 - P(a, x)\)
where
\(Gamma(a, x) = int_{x}^{\infty} t^{a-1} exp(-t) dt\)
is the upper incomplete Gama function.
Note, above P(a, x) (Igamma) is the lower regularized complete Gamma function.


Returns the imaginary part of a complex (or real) tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.imag, tf.compat.v1.math.imag
Given a tensor input, this operation returns a tensor of type float that is the imaginary part of each element in input considered as a complex number. If input is real, a tensor of all zeros is returned.


Computes the inverse permutation of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.invert_permutation, tf.compat.v1.math.invert_permutation
This operation computes the inverse of an index permutation. It takes a 1-D integer tensor x, which represents the indices of a zero-based array, and swaps each value with its index position. In other words, for an output tensor y and an input tensor x, this operation computes the following:
y[x[i]] = i for i in [0, 1, ..., len(x) - 1]
The values must include 0. There can be no duplicate values or negative values.


Says whether the targets are in the top K predictions.
Main aliases
tf.nn.in_top_k
This outputs a batch_size bool array, an entry out[i] is true if the prediction for the target class is finite (not inf, -inf, or nan) and among the top k predictions among all predictions for example i. Note that the behavior of InTopK differs from the TopK op in its handling of ties; if multiple classes have the same prediction value and straddle the top-k boundary, all of those classes are considered to be in the top k.
More formally, let
\(predictions_i\) be the predictions for all classes for example i, \(targets_i\) be the target class for example i, \(out_i\) be the output for example i,


Returns which elements of x are finite.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.debugging.is_finite, tf.compat.v1.is_finite, tf.compat.v1.math.is_finite
Equivalent to np.isfinite


Returns which elements of x are Inf.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.debugging.is_inf, tf.compat.v1.is_inf, tf.compat.v1.math.is_inf
Equivalent to np.isinf


Returns which elements of x are NaN.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.debugging.is_nan, tf.compat.v1.is_nan, tf.compat.v1.math.is_nan
Equivalent to np.isnan


Returns True if x is non-decreasing.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.debugging.is_non_decreasing, tf.compat.v1.is_non_decreasing, tf.compat.v1.math.is_non_decreasing
Elements of x are compared in row-major order. The tensor [x[0],...] is non-decreasing if for every adjacent pair we have x[i] <= x[i+1]. If x has less than two elements, it is trivially non-decreasing.
See also: is_strictly_increasing


Returns True if x is strictly increasing.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.debugging.is_strictly_increasing, tf.compat.v1.is_strictly_increasing, tf.compat.v1.math.is_strictly_increasing
Elements of x are compared in row-major order. The tensor [x[0],...] is strictly increasing if for every adjacent pair we have x[i] < x[i+1]. If x has less than two elements, it is trivially strictly increasing.
See also: is_non_decreasing


Normalizes along dimension axis using an L2 norm.
Main aliases
tf.linalg.l2_normalize, tf.nn.l2_normalize
For a 1-D tensor with axis = 0, computes
For x with more dimensions, independently normalizes each 1-D slice along dimension axis.


Computes \(ln(|Beta(x)|)\), reducing along the last dimension.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lbeta, tf.compat.v1.math.lbeta
Given one-dimensional $z = [z_1,...,z_K]$, we define
where $\Gamma$ is the gamma function.
And for $n + 1$ dimensional $x$ with shape $[N_1, ..., N_n, K]$, we define
In other words, the last dimension is treated as the $z$ vector.
Note that if $z = [u, v]$, then
which defines the traditional bivariate beta function.
If the last dimension is empty, we follow the convention that the sum over the empty set is zero, and the product is one.


Returns the truth value of (x < y) element-wise.
Main aliases
tf.less
See Migration guide for more details.
tf.compat.v1.less, tf.compat.v1.math.less


Returns the truth value of (x <= y) element-wise.
Main aliases
tf.less_equal
See Migration guide for more details.
tf.compat.v1.less_equal, tf.compat.v1.math.less_equal


Computes the log of the absolute value of Gamma(x) element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.lgamma, tf.compat.v1.math.lgamma
For positive numbers, this function computes log((input - 1)!) for every element in the tensor. lgamma(5) = log((5-1)!) = log(4!) = log(24) = 3.1780539


Computes natural logarithm of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.log, tf.compat.v1.math.log
I.e., \(y = \log_e x\).
x = tf.constant([0, 0.5, 1, 5]) tf.math.log(x)
See: https://en.wikipedia.org/wiki/Logarithm


Computes natural logarithm of (1 + x) element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.log1p, tf.compat.v1.math.log1p
I.e., \(y = \log_e (1 + x)\).


Logical AND function.
Main aliases
tf.logical_and
See Migration guide for more details.
tf.compat.v1.logical_and, tf.compat.v1.math.logical_and
The operation works for the following input types:


Returns the truth value of NOT x element-wise.
Main aliases
tf.logical_not
See Migration guide for more details.
tf.compat.v1.logical_not, tf.compat.v1.math.logical_not


Returns the truth value of x OR y element-wise.
Main aliases
tf.logical_or
See Migration guide for more details.
tf.compat.v1.logical_or, tf.compat.v1.math.logical_or


Logical XOR function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.logical_xor, tf.compat.v1.math.logical_xor
x ^ y = (x | y) & ~(x & y)
The operation works for the following input types:


Computes log sigmoid of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.log_sigmoid, tf.compat.v1.math.log_sigmoid
Specifically, y = log(1 / (1 + exp(-x))). For numerical stability, we use y = -tf.nn.softplus(-x).
If a positive number is large, then its log_sigmoid will approach to 0 since the formula will be y = log( <large_num> / (1 + <large_num>) ) which approximates to log (1) which is 0.
If a negative number is large, its log_sigmoid will approach to the number itself since the formula will be y = log( 1 / (1 + <large_num>) ) which is log (1) - log ( (1 + <large_num>) ) which approximates to - <large_num> that is the number itself.


Returns the max of x and y (i.e. x > y ? x : y) element-wise.
Main aliases
tf.maximum
See Migration guide for more details.
tf.compat.v1.math.maximum, tf.compat.v1.maximum


Returns the min of x and y (i.e. x < y ? x : y) element-wise.
Main aliases
tf.minimum
See Migration guide for more details.
tf.compat.v1.math.minimum, tf.compat.v1.minimum
Both inputs are number-type tensors (except complex). minimum expects that both tensors have the same dtype.
Note that minimum supports broadcast semantics.
If inputs are not tensors, they will be converted to tensors. See tf.convert_to_tensor.


Returns an element-wise x * y.
Main aliases
tf.multiply
See Migration guide for more details.
tf.compat.v1.math.multiply, tf.compat.v1.multiply
Since tf.math.multiply will convert its arguments to Tensors, you can also pass in non-Tensor arguments:
If x.shape is not thes same as y.shape, they will be broadcast to a compatible shape. (More about broadcasting here.)
A Tensor. Has the same type as x.


Computes the product of x and y and returns 0 if the y is zero, even if x is NaN or infinite.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.multiply_no_nan


Compute quantile of Standard Normal.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.ndtri


Computes numerical negative value element-wise.
Main aliases
tf.negative
See Migration guide for more details.
tf.compat.v1.math.negative, tf.compat.v1.negative
I.e., \(y = -x\).
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.negative(x.values, ...), x.dense_shape)


Returns the next representable value of x1 in the direction of x2, element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.nextafter
This operation returns the same result as the C++ std::nextafter function.
It can also return a subnormal number.
Equivalent to C++ std::nextafter function.


Returns the truth value of (x != y) element-wise.
Main aliases
tf.not_equal
See Migration guide for more details.
tf.compat.v1.math.not_equal, tf.compat.v1.not_equal
Performs a broadcast with the arguments and then an element-wise inequality comparison, returning a Tensor of boolean values.


Compute the polygamma function \(\psi^{(n)}(x)\).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.polygamma, tf.compat.v1.polygamma
The polygamma function is defined as:
\(\psi^{(a)}(x) = \frac{d^a}{dx^a} \psi(x)\)
where \(\psi(x)\) is the digamma function. The polygamma function is defined only for non-negative integer orders \a\.


Computes the elementwise value of a polynomial.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.polyval
If x is a tensor and coeffs is a list n + 1 tensors, this function returns the value of the n-th order polynomial
p(x) = coeffs[n-1] + coeffs[n-2] * x + ... + coeffs[0] * x**(n-1)
evaluated using Horner's method, i.e.
`p(x) = coeffs[n-1] + x * (coeffs[n-2] + ... + x * (coeffs[1]
tf.math.polyval can also be used in polynomial regression. Taking advantage of this function can facilitate writing a polynomial equation as compared to explicitly writing it out, especially for higher degree polynomials.
Equivalent to numpy.polyval.


Computes the power of one value to another.
Main aliases
tf.pow
See Migration guide for more details.
tf.compat.v1.math.pow, tf.compat.v1.pow
Given a tensor x and a tensor y, this operation computes \(x^y\) for corresponding elements in x and y. For example:


Returns the real part of a complex (or real) tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.real, tf.compat.v1.real
Given a tensor input, this operation returns a tensor of type float that is the real part of each element in input considered as a complex number.
If input is already real, it is returned unchanged.


Computes the reciprocal of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reciprocal, tf.compat.v1.reciprocal
I.e., \(y = 1 / x\).


Performs a safe reciprocal operation, element wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reciprocal_no_nan
If a particular element is zero, the reciprocal for that element is also set to zero.


Computes the "logical and" of elements across dimensions of a tensor.
Main aliases
tf.reduce_all
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.all


Computes the "logical or" of elements across dimensions of a tensor.
Main aliases
tf.reduce_any
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.any


Computes the Euclidean norm of elements across dimensions of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_euclidean_norm
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.


Computes log(sum(exp(elements across dimensions of a tensor))).
Main aliases
tf.reduce_logsumexp
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.
This function is more numerically stable than log(sum(exp(input))). It avoids overflows caused by taking the exp of large inputs and underflows caused by taking the log of small inputs.


Computes the maximum of elements across dimensions of a tensor.
Main aliases
tf.reduce_max
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
See the numpy docs for np.amax and np.nanmax behavior.


Computes the mean of elements across dimensions of a tensor.
Main aliases
tf.reduce_mean
Reduces input_tensor along the dimensions given in axis by computing the mean of elements across the dimensions in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.mean
Please note that np.mean has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.reduce_mean has an aggressive type inference from input_tensor, for example:


Computes the minimum of elements across dimensions of a tensor.
Main aliases
tf.reduce_min
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.min


Computes the product of elements across dimensions of a tensor.
Main aliases
tf.reduce_prod
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.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.prod


Computes the standard deviation of elements across dimensions of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_std
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.std
Please note np.std has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.math.reduce_std has aggressive type inference from input_tensor.


Computes the sum of elements across dimensions of a tensor.
Main aliases
tf.reduce_sum
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.sum apart the fact that numpy upcast uint8 and int32 to int64 while tensorflow returns the same dtype as the input.


Computes the variance of elements across dimensions of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.reduce_variance
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1.
If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Equivalent to np.var
Please note np.var has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.math.reduce_variance has aggressive type inference from input_tensor.


Returns element-wise integer closest to x.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.rint, tf.compat.v1.rint
If the result is midway between two representable values, the even representable is chosen. For example:


Rounds the values of a tensor to the nearest integer, element-wise.
Main aliases
tf.round
See Migration guide for more details.
tf.compat.v1.math.round, tf.compat.v1.round
Rounds half to even. Also known as bankers rounding. If you want to round according to the current system rounding mode use tf::cint. For example:


Computes reciprocal of square root of x element-wise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.rsqrt, tf.compat.v1.rsqrt


Multiplies a scalar times a Tensor or IndexedSlices object.
Main aliases
tf.scalar_mul
Intended for use in gradient code which might deal with IndexedSlices objects, which are easy to multiply by a scalar but more expensive to multiply with arbitrary tensors.


Computes the maximum along segments of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.segment_max, tf.compat.v1.segment_max
Read the section on segmentation for an explanation of segments.
Computes a tensor such that \(output_i = \max_j(data_j)\) where max is over j such that segment_ids[j] == i.
If the max is empty for a given segment ID i, output[i] = 0.


Computes the mean along segments of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.segment_mean, tf.compat.v1.segment_mean
Read the section on segmentation for an explanation of segments.
Computes a tensor such that \(output_i = \frac{\sum_j data_j}{N}\) where mean is over j such that segment_ids[j] == i and N is the total number of values summed.
If the mean is empty for a given segment ID i, output[i] = 0.


Computes the minimum along segments of a tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.math.segment_min, tf.compat.v1.segment_min
Read the section on segmentation for an explanation of segments.
Computes a tensor such that \(output_i = \min_j(data_j)\) where min is over j such that segment_ids[j] == i.
If the min is empty for a given segment ID i, output[i] = 0.