Basic operations 2 questions
##Exercise #3 # a. Create list baseball_height that contains data of the baseball players' height in inches baseball_height = [74, 69, 71, 73, 76, 79, 75, 81] #Use np.array() to create a numpy array from baseball_height. Name this array np_baseball_height. #Print out the type of np_baseball_height to check that you got it right. #convert the units to meters by Multiplying np_baseball_height with 0.0254. #Store the new values in a new array, np_baseball_height_m. #Print out np_baseball_height_m and check if the output makes sense. # b. Create list baseball_weight that contains data of the baseball players' weight in pounds baseball_weight = [174, 210, 181, 193, 230, 200, 185, 190] #Create a numpy array from the baseball_weight list. Name this array np_baseball_weight. #Multiply by 0.453592 to go from pounds to kilograms. Store the resulting numpy array as np_baseball_weight_kg. #Use np_baseball_height_m and np_baseball_weight_kg to calculate the BMI of each player. #Print out bmi #c. Create a boolean numpy array: the element of the array should be True if the corresponding #baseball player's BMI is below 21. You can use the < operator for this. Name the array light. #Print the array light. # Print out a numpy array with the BMIs of all baseball players whose BMI is below` 21. #Use light inside square brackets to do a selection on the bmi array. ##2D NumPy Arrays #Type of NumPy Arrays type(np_height) #Out: numpy.ndarray type(np_weight) #Out: numpy.ndarray #ndarray = N-dimensional array np_2d = np.array([[1.73, 1.68, 1.71, 1.89, 1.79], [65.4, 59.2, 63.6, 88.4, 68.7]]) np_2d #Out:array([[ 1.73, 1.68, 1.71, 1.89, 1.79], # [ 65.4 , 59.2 , 63.6 , 88.4 , 68.7 ]]) np_2d.shape #(2, 5); 2 rows, 5 columns np.array([[1.73, 1.68, 1.71, 1.89, 1.79], [65.4, 59.2, 63.6, 88.4, "68.7"]]) #array can contains only one type #array([['1.73', '1.68', '1.71', '1.89', '1.79'], # ['65.4', '59.2', '63.6', '88.4', '68.7']], # dtype='<U32') #Subsetting np_2d[0] #Out: array([ 1.73, 1.68, 1.71, 1.89, 1.79]) np_2d[0][2] #Out: 1.71 np_2d[0,2] #Out: 1.71 np_2d[:,1:3] #array([[ 1.68, 1.71], #[ 59.2 , 63.6 ]]) np_2d[1,:] #Out: array([ 65.4, 59.2, 63.6, 88.4, 68.7]) #2D Arithmetic np_mat = np.array([[1, 2], [3, 4], [5, 6]]) np_mat * 2 np_mat + np.array([10, 8]) np_mat + np_mat np_mat*3 ##Exercise #4 # Create baseball, a list of lists, the first column represents weight and the second #column represents height baseball = [[180, 78.4], [215, 102.7], [210, 98.5], [188, 75.2]] #a. Use np.array() to create a 2D numpy array from baseball. Name it np_baseball. #Print out the type of np_baseball. #b. Print out the shape attribute of np_baseball. Use np_baseball.shape. #c. Print out the 3rd row of np_baseball. #d. Make a new variable, np_weight, containing the entire first column of np_baseball. #e. Select the height (second column) of the 2nd baseball player in np_baseball and print it out. #f. You want to convert the units of height and weight, i.e. from pound to kg and inches to meter #As a first step, create a numpy array with two values: 0.453592, 0.0254 and name this
#array factors. Multiply np_baseball with factors and print out the result.
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
