Order from us for quality, customized work in due time of your choice.
##Exercise #3
# a. Create list baseball_height that contains data of the basebal
##Exercise #3 Order from us for quality, customized work in due time of your choice.
# 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='