Week-10 Assessment: Sample Questions

[ Question 1 ] [ Question 2 ]

Based on your justifications and answers, your tutor will award you marks. You don't need to offer long justifications, as far as your tutor understands it, that's fine. In case your answer in Python (numpy) is incorrect, your tutor will award you partial marks based on your problem-solving approach and explanations.

Question 1

For the data set "data_sea_ice" used in the lab07 and lab09, provide a numpy code segment for the following task(s).

Tasks:

For your quick reference, the following code segment is from the lab09.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ENGG1811 Lab

Data analysis on sea ice (Part 2)
"""

# %% Import packages
import numpy as np
import matplotlib.pyplot as plt 

# %% Preliminary processing 
# Load data and store it as a numpy array called data_sea_ice
data_sea_ice = np.loadtxt('sea_ice.txt')

# Extract information on year from data_sea_ice
years = data_sea_ice[:,0];   # first column
years = years.astype(int)    # change data type to int
data_sea_ice = np.delete(data_sea_ice,0,axis=1)   # remove the first column 

# Array on months 
months = np.linspace(0.5,12,24)

# The sea ice data began in year 1979 and lasted until 2013 (35 years)
# There are 24 half-monthly measurements per year

# years is the numpy array [1979, 1980, ..., 2013]
# months is the numpy array [0.5, 1, 1.5, ..., 12]
# data_sea_ice is a numpy array of shape (35,24) containing 
# sea ice extent 

# %% ****************************
# Please insert your code below 


Answers (also provide brief justifications):

1) 
avg_sea_ice = np.mean(data_sea_ice)

2) 
np.sum(data_sea_ice > avg_sea_ice, axis=1)