Intro to Programming with Python - Assignment 6
Intro to Programming with Python - Assignment 6
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.
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:
• Select the customers that survived, calculate the Male and Female ratio of the survived
customers.
• 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