def sparse_dummyvar(partitions):
    num_rows = np.sum(np.max(partitions, axis=1))
nnz = np.prod(partitions.shape)
as_part = np.argsort(partitions, axis=1)
s_part = np.sort(partitions, axis=1)
mask = np.hstack(([[True]] * len(items_per_row), s_part[:, :-1] != s_part[:,
    1:]))
indptr = np.where(mask.ravel())[0]
indptr = np.append(indptr, nnz)
return sps.csr_matrix((np.repeat([1], nnz), as_part.ravel(), indptr), shape
    =(num_rows, partitions.shape[1]))
numpy equivalent of matlab dummyvar