[ Question 1 ] [ Question 2 ]
Task:
#!/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) np.mean(data_sea_ice[np.ix_((2000 <= years) & (years <= 2009), months <= 6)]) OR rows_mask = (2000 <= years) & (years <= 2009) cols_mask = (months <= 6) selected_data = data_sea_ice[np.ix_(rows_mask , cols_mask ) ] np.mean(selected_data)