Skip to content

Instantly share code, notes, and snippets.

@singularitti
Last active April 12, 2025 18:14
Show Gist options
  • Save singularitti/5e6be700f92bd0c35bc620ba2eb7fcc7 to your computer and use it in GitHub Desktop.
Save singularitti/5e6be700f92bd0c35bc620ba2eb7fcc7 to your computer and use it in GitHub Desktop.
Get off-diagonal elements of a matrix #Julia #linear-algebra
# From https://discourse.julialang.org/t/41169/7
offdiag(A::AbstractMatrix) = [A[ι] for ι in CartesianIndices(A) if ι[1] ≠ ι[2]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment