Skip to content

Instantly share code, notes, and snippets.

@kumanna
Created February 5, 2024 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumanna/5efff789f0f5965236c3920026aa4dce to your computer and use it in GitHub Desktop.
Save kumanna/5efff789f0f5965236c3920026aa4dce to your computer and use it in GitHub Desktop.
import numpy as np
A = np.array([[ 1, 0, 1, 0],
[-1, 1, 0, 1],
[ 0, -1, 0, -1],
[ 0, 0, -1, 0],
[ 0, 0, 0, 0]])
def cluster_columns(M):
column_dict = {}
for i in range(M.shape[1]):
t = tuple(M[:,i])
if t in column_dict:
column_dict[t] += 1
else:
column_dict[t] = 1
return column_dict
print(cluster_columns(A))
A_dropped_0 = np.array(list(cluster_columns(A).keys())).T
print(A_dropped_0)
print("Alternatively:")
A_dropped = np.array([i for i in set([tuple(A[:,i]) for i in range(A.shape[1])])]).T
print(A_dropped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment