
3310487509
Jul 20, 2022, updated at Jul 28, 2022 (UTC)
Permutation matrix multiplication in Python
I'm a beginner in Python and i think i cannot seem to understand it well, so wanted to understand the concept of Permutation matrices. A and B are square and contain only a single 1 in each row. All of the rows are unique. I've added my first attempt as an answer.
I hope someone has a faster solution to this. Thanks in advance!
def permmult(a, b):
"""Multiply two permutation matrices.
a,b: lists of positive integers and zero."""
c =
for row in a:
c.append(b[-row])
return c
I hope someone has a faster solution to this. Thanks in advance!
Please also mark the comments that contributed to the solution of the article
Content-ID: 3388232208
Url: https://rootdb.com/en/permutation-matrix-multiplication-in-python-3388232208.html
Printed on: February 23, 2025 at 07:02 o'clock
1 Comment
Hi,
I think you should have a look at itertools: https://docs.python.org/3/library/itertools.html
max
I think you should have a look at itertools: https://docs.python.org/3/library/itertools.html
import itertools
print(list(itertools.permutations([1,2,3])))
max