Skip to content

Instantly share code, notes, and snippets.

@larsbratholm
Last active March 13, 2019 15:19
Show Gist options
  • Save larsbratholm/243d4916bf33a129b226ad5e076046c5 to your computer and use it in GitHub Desktop.
Save larsbratholm/243d4916bf33a129b226ad5e076046c5 to your computer and use it in GitHub Desktop.
Example showing np.ix_
import numpy as np
import copy
K # shape (N,N)
# Create a list with all the indices of the submatrix
idx = np.arange(N-1) + 1
for i in range(N):
# when i==0, idx will be [1,2,3,4...]
# when i==1, idx will become [0,2,3,4...] etc
if i > 0:
idx[i] -= 1
# Construct the submatrix using np.ix_
sub_K = K[np.ix_(sub_idx,sub_idx)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment