3310487509
20.07.2022, aktualisiert am 28.07.2022
3327
1
0
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!
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 3388232208
Url: https://administrator.de/en/permutation-matrix-multiplication-in-python-3388232208.html
Ausgedruckt am: 22.12.2024 um 11:12 Uhr
1 Kommentar
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