The permutation vector must be interpreted sequentially. If piv=[1,2,2], then you must do the following (with zero indexing):
- Line 0 is changed using line 1
- New line 1 is changed using line 2 and
- The new Row 2 remains the same.
In code, this would do the trick:
P = np.eye(3)
for i, p in enumerate(piv):
Q = np.eye(3,3)
q = Q[i,:].copy()
Q[i,:] = Q[p,:]
Q[p,:] = q
P = np.dot(P, Q)
For piv=[1,2,2]P there is
[[ 0. 0. 1.]
[ 1. 0. 0.]
[ 0. 1. 0.]]
, , P, .