def full2sparse(vec, eps=1e-09):
 vec = np.asarray(vec, dtype=float)
 nnz = np.nonzero((abs(vec) > eps))[0]
 return list(zip(nnz, vec.take(nnz)))

def full2sparse ( vec , eps = 1e-09 ) : vec = np . asarray ( vec , dtype = float ) nnz = np . nonzero ( ( abs ( vec ) > eps ) ) [ 0 ] return list ( zip ( nnz , vec . take ( nnz ) ) )
convert a dense np array into the sparse document format .