0% found this document useful (0 votes)
5 views

Intro to Programming with Python - Assignment 6

Assignment 6 for BANA3020 requires students to implement matrix vector multiplication using Numpy arrays and create a function for sparse matrices. Additionally, students will analyze the Titanic data set by calculating survival ratios, creating a new column, and performing various statistical analyses and visualizations. Submissions are due by January 3rd, 2025, and must follow specific formatting and academic honesty guidelines.

Uploaded by

Thanh Doãn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Intro to Programming with Python - Assignment 6

Assignment 6 for BANA3020 requires students to implement matrix vector multiplication using Numpy arrays and create a function for sparse matrices. Additionally, students will analyze the Titanic data set by calculating survival ratios, creating a new column, and performing various statistical analyses and visualizations. Submissions are due by January 3rd, 2025, and must follow specific formatting and academic honesty guidelines.

Uploaded by

Thanh Doãn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 6

BANA3020 Introduction to Programming Fall 2024 – Assignment 6

Assignment Submission Instructions:

• Due date: Jan 3rd, 2025


• Your program should work correctly on all inputs. If there are any specifications about
how the program should be written (or how the output should appear), those specifications
should be followed.
• Your code and functions/modules should be appropriately commented. However, try to
avoid making your code overly busy (e.g., include a comment on every line).
• Variables and functions should have meaningful names, and code should be organized
into functions/methods where appropriate.
• Academic honesty is required in all work you submit to be graded. You MUST NOT copy
or share your code with other students to avoid plagiarism issues.
• Use the template provided to prepare your solutions.
• Upload your work to Canvas as a .py file.
• Submit separate .py file for each problem with the following naming format: Assign-
ment1_Q1.py. Failure to submit a .py file for lab or assignment will result in a 0. Note: If
you are working on Jupiter Notebook, you need to download/convert it to Python .py file
for submission.
• Late submission of an assignment without an approved extension is NOT allowed.

Assignment № 6 Page 1
Matrix vector multiplication using Numpy arrays

In Assignment 4, you have implemented matrix vector multiplication where matrix and vectors
are stored in list. In this problem, you will implement the same function for matrix vector multipli-
cation where matrix and vectors are numpy arrays. The function should work exactly the same
way as the one in Assignment 4.
Hint: You can use attribute shape to find the dimension of a numpy array. Then you can write
for loops similar to what you can do with list.

Sparse matrix

A sparse matrix is matrix where most of the elements in the matrix are zeros. In this problem,
you will create a function sparse() that takes an input parameter as a matrix. The function returns
the followings:

• A vector v that stores all the non-zero elements of the matrix. Hint: You can use the
"where" function to find out how long this vector has to be. To create a vector of all zero
values, use the function "numpy.zeros". Numpy Zeros

• A vector r which has the same length as vector v. Vector r stores the row index of the
corresponding value in vector v.

• A vector c which has the same length as vector v. Vector c stores the column index of the
corresponding value in vector v.

For instance, an input matrix A can be represented as vectors v, r, c as followings :


       
0 1 0 1 0 1
       
A= −1 0 0 v = −1 r = 1 c = 0
      
0 0 5 5 2 2

Titanic data set

In this problem, we will work with the Titanic data set from the lecture. The details of the data
set can be found here: Titanic data. Make sure you read the data set description to know the
column names. Perform the following tasks using Numpy, Pandas, and Matplotlib:

• Read the data set from the attached file ’titanic.csv’.

• Select the customers that survived, calculate the Male and Female ratio of the survived
customers.

• Do the same for those who did not survive.

• Create a new data column called "Aquaintance" that is the sum of the column ’SibSp’ and
’Parch’.

Assignment № 6 Page 2
• Perform a scatter plot between column ’Age’ and ’Fare’. Do you observe any pattern?

• Calculate the average age of all customers, of survived customers, of non-survive cus-
tomers. You can use the sum() or mean() function.

• Calculate the average Fare paid of all customers, of survived customers, of non-survive
customers.

Assignment № 6 Page 3

You might also like