Created
February 5, 2024 13:43
-
-
Save kumanna/5efff789f0f5965236c3920026aa4dce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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