#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811. Illustrating numpy Boolean (Part 2) """ import numpy as np # Illustrating elementwise logical_and() array1 = np.array([ [ 3.2, 0.5, 5.8], [ 6, -1.2, 7.1]]) array1_la = np.logical_and(array1 > 3,array1 < 7) print(array1_la) # %% Quiz # The temperature data temp_list = 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 # Let us say the normal temperature range # is between [0.25,0.85] inclusively # For each thermometer, determine the number # of times that the thermometer reading is # outside the normal range # We expect [2, 6, 6, 3, 5] # Solution 0: Using logical_or # Solution 1: Using logical_not and logical_and