Skip to content

Instantly share code, notes, and snippets.

@wrwr
Created June 5, 2017 05:37
Show Gist options
  • Save wrwr/f0bd773521840623202c7f5ac002c3a2 to your computer and use it in GitHub Desktop.
Save wrwr/f0bd773521840623202c7f5ac002c3a2 to your computer and use it in GitHub Desktop.
Load and save csr_matrix dataset as numpy npz file
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