Here is an example, where we test if the Frobenius norm of the difference between the matrix consisting of the diagonal elements of x and x itself is less than some tolerance.
is_diagonal <- function(x, tol = 1e-8) {
norm(diag(diag(x)) - x, "F") < tol
}
Here is an example, where we test if the Frobenius norm of the difference between the matrix consisting of the diagonal elements of
x
andx
itself is less than some tolerance.