Created
May 19, 2019 01:05
-
-
Save fufufukakaka/326f3161a209291b377138b50b105395 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
def fast_access_sparse_matrix(idx, row, sparse_matrix): | |
# index | |
start, stop = sparse_matrix.indptr[idx], sparse_matrix.indptr[idx+1] | |
index_data = sparse_matrix.data[start:stop] | |
index_rows = sparse_matrix.indices[start:stop] | |
# row | |
## find row index | |
if row in index_rows: | |
row_index = np.where(index_rows==row)[0][0] | |
extract_elements = index_data[row_index] | |
else: | |
extract_elements = 0 | |
return extract_elements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment