#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811. Illustrating numpy Boolean (Part 1) """ 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]]) # Relational operator array1_cp0 = array1 > 2 # %% Quiz: # # What is array1 < 5? # Think about what the answer should be before running the command. #%% Counting the number of Trues # Count the number of entries exceeding 2 # in each row of array2 np.sum(array1 > 2, axis=1) # Can also use np.sum(array1_cp0, axis=1) where array1_cp0 is # assigned in Line 17