Skip to content

Instantly share code, notes, and snippets.

@sayakpaul
Created June 21, 2020 15:45
Show Gist options
  • Save sayakpaul/892d58eadadfde68bf2b8d23711e980c to your computer and use it in GitHub Desktop.
Save sayakpaul/892d58eadadfde68bf2b8d23711e980c to your computer and use it in GitHub Desktop.
# Copy the kernel weights and get ranked indices of the
# column-wise L2 Norms
kernel_weights = np.copy(k_weights)
ind = np.argsort(np.linalg.norm(kernel_weights, axis=0))
# Number of indices to be set to 0
sparsity_percentage = 0.7
cutoff = int(len(ind)*sparsity_percentage)
# The indices in the 2D kernel weight matrix to be set to 0
sparse_cutoff_inds = ind[0:cutoff]
kernel_weights[:,sparse_cutoff_inds] = 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment