The purpose of the lab is to practice and measure one’s preparation: the exercises are not too difficult, if you have followed the lectures. However, no score is put on them.
Working mode: students should work independently or in small groups, without disturbing colleagues. Group work is fruitful only if everyone participates and if everyone writes their own solution for all exercises.
The teacher will try as much as possible not to occupy the time of the laboratory to introduce new material, although sometimes this will be necessary. The lecturer is available to help students, who can start working even before the lecturer arrives in the classroom, if they wish.
Recommendations: Read the text of the exercises carefully before ask for clarification. In any case, I will be in the classroom with you.
Using test files: To help you complete this exercise you have test programs available to test your solution. These are similar to those you will have on the exam, so I recommend that you learn how to use them. To complete the exercise you will need to
python3 <fileditest>
command in that
folder;where <fileditest>
should obviously be replaced by
the name of the test appropriate for the exercise you are working on.
For each exercise there is an independent test file, so that you can
easily work on the exercises one at a time.
The result of each test is a screen(s) in which it is shown:
For each function written, calls are made with different values of the parameters. The outcome of the tests is reported with the character
E
if the call cannot be executed,F
if the function does not return the correct
result,.
if the function returns the correct result.Write a function mat_sum(m)
that:
m
, represented as a list of
lists;m
.We represent an r × c matrix in Python as a
list with length r, where each
element is a list of length c.
You may assume that the argument is well formed, with r ≥ 1, c ≥ 1, and all the lists
representing rows contain c
numeric elements.
Python code must be saved in file: mat_sum.py
Test file (download by right click): test_mat_sum.py
Write a function mat_min(m)
that:
m
, represented as a list of
lists;m
.We represent an r × c matrix in Python as a
list with length r, where each
element is a list of length c.
You may assume that the argument is well formed, with r ≥ 1, c ≥ 1, and all the lists
representing rows contain c
numeric elements.
Python code must be saved in file: mat_min.py
Test file (download by right click): test_mat_min.py
Write a function mat_posmax(m)
that:
m
;return i, j
, that
are the row and column indices where the maximum element in the matrix
appears. In case of more maxima, the position of the first occurrence
must be returned (minimum row index, and in case of more maxima in that
row minimum column index)Python code must be saved in file: mat_posmax.py
Test file (download by right click): test_mat_posmax.py
Write a function mat_sumdiagonal(m)
that:
m
, represented as a
list of lists;m
.We represent an r × c matrix in Python as a
list with length r, where each
element is a list of length c.
You may assume that the argument is well formed, with r ≥ 1, c = r, and all the lists
representing rows contain c
numeric elements.
Python code must be saved in file:
mat_sumdiagonal.py
Test file (download by right click): test_mat_sumdiagonal.py
Write a function mat_row_sums(m)
that:
m
, represented as a list of
lists;i
is the sum of all
elements in row i
of m
. The length of the
returned list is equal to the number of rows in m
.We represent an r × c matrix in Python as a
list with length r, where each
element is a list of length c.
You may assume that the argument is well formed, with r ≥ 1, c ≥ 1, and all the lists
representing rows contain c
numeric elements.
Python code must be saved in file: mat_row_sums.py
Test file (download by right click): test_mat_row_sums.py
Write a function mat_col_sums(m)
that:
m
, represented as a list of
lists;i
is the sum of all
elements in column i
of m
. The length of the
returned list is equal to the number of columns in m
.We represent an r × c matrix in Python as a
list with length r, where each
element is a list of length c.
You may assume that the argument is well formed, with r ≥ 1, c ≥ 1, and all the lists
representing rows contain c
numeric elements.
Python code must be saved in file: mat_col_sums.py
Test file (download by right click): test_mat_col_sums.py
Write a function mat_posmaxrow(m)
that:
takes as argument a matrix m
, represented as a list
of lists;
returns the position of the row having maximum sum. E.G., if called with argument
[ [2, 4, 3, 6, 8], [3, 1, 4, 0, 0], [9, 5, 9, 7, 4] ]
value 2 should be returned, since row 2 has sum 34, while rows in position 0 and 1 have sum 23 and 8 respectively.
We represent an r × c matrix in Python as a
list with length r, where each
element is a list of length c.
You may assume that the argument is well formed, with r ≥ 1, c ≥ 1, and all the lists
representing rows contain c
numeric elements.
Python code must be saved in file: mat_posmaxrow.py
Test file (download by right click): test_mat_posmaxrow.py