Constructing a permutation matrix

Nope. It implements the transposed getindex operation, so it is equivalent to P^T. Even if you fix that so that it is the right matrix, it implements A * P as A[:, P.p], which is then equivalent to AP^T. (Even if you reinterpret what you mean by the “permutation vector” p to make his P correct, his A * P and P * A were inconsistent.) You can’t tell for your example P, since that matrix happened to be symmetric.

That’s why I gave the corrected implementation in my post.

2 Likes