B
B
bergentroll2017-02-19 13:31:19
Python
bergentroll, 2017-02-19 13:31:19

How to iterate over nth order matrix minors in python?

I solve the problem "to implement the Gauss method". I can not give birth to an algorithm for a function that would take a matrix and the order of a minor as an argument and go through all the minors of the corresponding order.
The problem boils down to a simpler one: there is a set, how to iterate over all combinations of an arbitrary number of elements?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1011, 2017-02-19
@bergentroll

The problem boils down to a simpler one: there is a set, how to iterate over all combinations of an arbitrary number of elements?
Kombnatorika is an interesting thing. here are the solutions:
http://ru.stackoverflow.com/questions/154252/All-in...

A
aRegius, 2017-02-19
@aRegius

... how to iterate over all combinations of an arbitrary number of elements?

Using the permutations function of the itertools module :
>>> import itertools
>>> num = '123'
>>> list(itertools.permutations(num))
[('1', '2', '3'), ('1', '3', '2'), ('2', '1', '3'), ('2', '3', '1'), ('3', '1', '2'), ('3', '2', '1')]
>>> letters = ['A', 'B', 'C']
>>> list(itertools.permutations(letters))
[('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question