Skip to content

Instantly share code, notes, and snippets.

@alexsavio
Last active August 29, 2015 14:05
Show Gist options
  • Save alexsavio/6ccb367f3583e65aa5b4 to your computer and use it in GitHub Desktop.
Save alexsavio/6ccb367f3583e65aa5b4 to your computer and use it in GitHub Desktop.
One liner for loop on upper diagonal indices of a square matrix (n_elems X n_elems) (k=0 to include the diagonal)
import numpy as np
for x_idx, y_idx in zip(*np.triu_indices(n_elems, k=1)):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment