age=np.array([15,17,19,20,14,21,16,19,13,20,22,23,21,16,18,19,20,15,17,18])height=np.array([156,144,180,162,152,157,154,155,151,150,158,179,126,182,183,154,159,160,172,149])Given age and height of 20 students in two different numpy arrays with name age and height (in cms). Print the age of those students whose height is above 155 cm.Print the Numpy array.
Question
age=np.array([15,17,19,20,14,21,16,19,13,20,22,23,21,16,18,19,20,15,17,18])height=np.array([156,144,180,162,152,157,154,155,151,150,158,179,126,182,183,154,159,160,172,149])Given age and height of 20 students in two different numpy arrays with name age and height (in cms). Print the age of those students whose height is above 155 cm.Print the Numpy array.
Solution
The language of the text is Python. Here is the solution:
import numpy as np
# given data
age = np.array([15,17,19,20,14,21,16,19,13,20,22,23,21,16,18,19,20,15,17,18])
height = np.array([156,144,180,162,152,157,154,155,151,150,158,179,126,182,183,154,159,160,172,149])
# get the ages of students whose height is above 155 cm
ages_of_students_with_height_above_155cm = age[height > 155]
# print the result
print(ages_of_students_with_height_above_155cm)
This script first imports the numpy module. Then it defines two numpy arrays, age and height, with the given data. The expression height > 155 creates a boolean array of the same shape as height, where each element indicates whether the corresponding student's height is above 155 cm. This boolean array is used to index age, resulting in a new array that contains only the ages of students whose height is above 155 cm. Finally, this array is printed to the console.
Similar Questions
A list named studentAge stores age of students of a class. Write thePython command to import the required module and (using built-infunction) to display the most common age value from the given list.
Given the following:name=["Kim","Bob","Jose","Selena","Chou"]ages=[19,22,21,24,31]Write a program using a for loop that prints: Kim 19Bob 22Jose 21Selena 24
import numpy as npnp_marks = np.array( [23, 21, 18, 25, 12, 18, 10] )print( np_marks[ (np_marks >= 15) ] )
Create a numpy array from height_in. Name this new array np_height_in
32. The table below shows the age of each employee at a cardboard box factory ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 AGE 51 39 34 27 23 43 41 55 24 25 38 17 21 37 35 38 31 24 Calculate the following summary statistics for the age feature using python (num py) code snippet: a. Minimum,Maximum, Range b.Mean and Medianc. Variance and Statnard deviation
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.