idx_dtype = get_index_dtype(maxval=max(self.shape))
data = np.asarray(_list(self.values()), dtype=self.dtype)
indices = np.asarray(_list(self.keys()), dtype=idx_dtype).T
A = coo_matrix((data, indices), shape=self.shape, dtype=self.dtype)
A.has_canonical_format = True
return A
After Change
idx_dtype = get_index_dtype(maxval=max(self.shape))
data = np.fromiter(itervalues(self), dtype=self.dtype, count=self.nnz)
I = np.fromiter((i for i,_ in iterkeys(self)), dtype=idx_dtype, count=self.nnz)
J = np.fromiter((j for _,j in iterkeys(self)), dtype=idx_dtype, count=self.nnz)
A = coo_matrix((data, (I, J)), shape=self.shape, dtype=self.dtype)
A.has_canonical_format = True
return A