numpy separate matrix to diagonal and the rest code example Example: numpy get diagonal matrix from matrix np.diag(np.diag(x))