Nov-22-2019, 09:14 PM
Hello folks,
I'm a physics student with a single module in python which isn't supported with detailed notes on how to do things! I'm hoping for some help with the code below.
I've been given four pieces of data for four students - (i) name, (ii) average exam result, (iii) no. of exams "soft-failed", (iv) no. of exams "hard-failed".
Amy 54 1 0
Bob 56 0 1
Carol 72 0 0
Dave 34 3 0
Question part a. states: Define a 2D NumPy array called results containing the numerical data given in the table (not the names or column headings), and a 1D NumPy array called names containing the four student names. I've done this (see code below).
I'm stuck on the next part of the homework which is as follows:
b. Calculate a Boolean array containing logical values which are True if the student progresses and False if they don't. For full marks, do this in one line of code.
c. By applying a logical array to select array indices, extract the rows from your array results relating to just the data for the students who have failed. Also extract the names of the students who have failed from names.
I've tried to do part b as you can see, but not with one line of code ...? And don't know how to do part c??
For part (b) I think I need to change the code so that I get an array with True values when the values in column 0 are >= 40 and the value in column 2 are 0 ...?
I'm a physics student with a single module in python which isn't supported with detailed notes on how to do things! I'm hoping for some help with the code below.
I've been given four pieces of data for four students - (i) name, (ii) average exam result, (iii) no. of exams "soft-failed", (iv) no. of exams "hard-failed".
Amy 54 1 0
Bob 56 0 1
Carol 72 0 0
Dave 34 3 0
Question part a. states: Define a 2D NumPy array called results containing the numerical data given in the table (not the names or column headings), and a 1D NumPy array called names containing the four student names. I've done this (see code below).
I'm stuck on the next part of the homework which is as follows:
b. Calculate a Boolean array containing logical values which are True if the student progresses and False if they don't. For full marks, do this in one line of code.
c. By applying a logical array to select array indices, extract the rows from your array results relating to just the data for the students who have failed. Also extract the names of the students who have failed from names.
I've tried to do part b as you can see, but not with one line of code ...? And don't know how to do part c??
import numpy as np import matplotlib.pyplot as plt results = np.array([[54, 1, 0], [56, 0, 1], [72, 0, 0], [34, 3, 0]]) names = np.array(['Amy', 'Bob', 'Carol', 'Dave']) results_colmn = results[:, 0] progress = results_colmn>=40
For part (b) I think I need to change the code so that I get an array with True values when the values in column 0 are >= 40 and the value in column 2 are 0 ...?