#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811. Illustrating the numpy functions all and any """ import numpy as np # Problem parameters array1 = np.array([ [-3.2, 0, 0.5, 5.8], [ 6, -4, 6.2, 7.1], [ 3.8, 5, 2.7, 3.7]]) # Using all and any print(np.all(array1 > 0, axis = 1)) print(np.any(array1 > 6, axis = 0)) # %% Quiz # The temperature data temp_array = np.array( [[ 0.3, 0.4, 0.5, 0.5, 0.1, 0.8, 0.8, 0.5, 0.0, 0.7], [ 0.2, 0.4, 0.8, 0.4, 0.8, 1.8, 0.9, 0.1, 1.4, 1.7], [ 1.1, 0.1, 0.8, 0.9, 0.5, 0.3, 0.2, 0.2, 1.1, 0.4], [ 0.4, 0.7, 0.6, 0.6, 0.4, 0.4, 0.5, 0.0, 0.1, 0.2], [ 0.2, 0.1, 0.9, 0.9, 0.3, 0.5, 0.4, 0.7, 0.2, 0.7]] ) # Each row contains data from a thermometer # # Each column contains the daily readings from the five # thermometers # # For normal operation, the temperature readings for # all thermometers in a day must be # strictly smaller 1.2 # Question: How many normal operation days were there? days_normal = np.all(temp_array < 1.2, axis = 0) np.sum(days_normal) # Can merge into one line np.sum(np.all(temp_array < 1.2, axis = 0)) # %% Forum question # After learning about where() # If column 0 is day 0, column 1 is day 1, # determine the indices of the days where the operation # was not normal