Created
June 5, 2017 05:37
-
-
Save wrwr/f0bd773521840623202c7f5ac002c3a2 to your computer and use it in GitHub Desktop.
Load and save csr_matrix dataset as numpy npz file
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 | |
from scipy.sparse import csr_matrix | |
def save_dataset(filename, x, y): | |
np.savez(filename, data=x.data, indices=x.indices, | |
indptr=x.indptr, shape=x.shape, target=y) | |
def load_dataset(filename): | |
loader = np.load(filename) | |
return csr_matrix((loader['data'], loader['indices'], loader['indptr']), | |
shape=loader['shape']), loader['target'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment