#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 Lecture Using numpy to count the number of times exceeding a threshold """ # %% Problem parameters # # Create a list of lists temp_list = [[ 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 list contains data from a thermometer # The threshold is 1 # Want to see the number of data points exceeding the threshold for each # thermometer # %% # import numpy import numpy as np # set the threshold threshold = 1 # convert the list to an numpy array temp_array = np.array(temp_list) # count the number of data points exceeding the threshold per thermometer count_exceeding = np.sum(temp_array > threshold, axis = 1)