np.eye(nz) changed to np.eye(len(nz))