what should the result of permutations([1,2,1]) be?
do we need to take into account a scenario of repeating elements in the list?
Formally a permutation does not consider repeating elements, therefore the permutations of [1,2,1] are [1,2] and [2,1].
However, in this question you can ASSUME that the input of the permutations function does not have repeating elements and you do not need to deal with repeating elements, since we write this function with a specific use in mind - determinant calculation.
This is the output of prettyprint in my computer:
'[2, 1, 1, 1]\n[1, 3, 1, 1]\n[1, 1, 6, -4]\n[1, 1, 1, 1]'
How do I fix it?
היי.. יש לי בעיה עם הפקודה
'int' object is not iterable
למה זה קורה זו לא פקודה מוגדרת?
איך אני בונה
חדש שזהה ל
נגיד משהו כמו
כי אני לא רוצה לשנות את הערכים של self
צריך לבנות חדשה ולהעתיק איבר איבר?
Initiate a new Matrix and copy the rows of the original to it.
Right. See for example in getitem in the slice section.
is there a problem to use copy.deep copy for that purpose?
Implementation of the minor(i,j) function should regard the matrix index in python terms right? (meaning that when I call minor(1,2) it should remove the second row and the third column).
Yes, everything should work on numbering that begins with "0".
to write argmin in one line, can we assume lst is a non empty list? (or at least just a list)
You can assume lst is either a list or a tuple.
You can raise a ValueError if lst is empty - like min does - or you can assume it is non-empty.
argmin can't work for a tuple with only one object, python recognizes it as the object's type, not a tuple:
>>> type() <class 'list'> >>> type((1)) <class 'int'>
How should we handle an empty Matrix? In the minor function (also, in the function - if we have a 1x1 matrix, should we assert or return and empty one) and in the determinant calculation - assert or return 0?
And as addition - how should we operate minor() on a Matrix with only one column or line?
Taking a minor when it is not possible - the matrix has one or zero cols or rows - should cause an error of your choosing (AssertionError is good enough).
The determinant of a 1x1 matrix is well defined.
You should not allow to initialize an empty matrix (0x0, 0x1, 1x0).