Lab activity

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

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


Sum elements of a numeric matrix

Write a function mat_sum(m) that:

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


Minimum element in a numeric matrix

Write a function mat_min(m) that:

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


Maximum element position in a numeric matrix

Write a function mat_posmax(m) that:

Python code must be saved in file: mat_posmax.py

Test file (download by right click): test_mat_posmax.py


Sum of elements in the diagonal of a squared numeric matrix

Write a function mat_sumdiagonal(m) that:

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


Row sums of a numeric matrix

Write a function mat_row_sums(m) that:

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


Column sums of a numeric matrix

Write a function mat_col_sums(m) that:

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


Position of row having maximum sum

Write a function mat_posmaxrow(m) that:

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