I
I
Ingvar Von Bjork2018-07-15 09:48:20
Python
Ingvar Von Bjork, 2018-07-15 09:48:20

How to loop through sums of elements line by line?

There is some 3x3 array (although it can be of any size). It is necessary to calculate the sums of elements in rows, for example:
1 2 3
4 5 6
7 8 9
summ1 = 1 + 5 + 9 (i.e. 1 element is skipped in the second row and the first and second in the third)
summ2 = 1 + 6 + 8
summ3 = 2 + 4 + 9
summ4 = 2 + 6 + 7
...
Is there a function to do this? Well, or push the idea of ​​\u200b\u200bhow to do it yourself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viva33, 2018-08-04
@Viva33

Use itertools.permutations to generate all permutations. Go through them in a cycle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question