Who's above average?
Boolean arrays can be a very powerful way to subset arrays. In this exercise, you will identify the prices that are greater than average from a list of prices.
numpy is imported as np and the array prices is available in your workspace.
This exercise is part of the course
Introduction to Python for Finance
Exercise instructions
- Find elements in
pricesthat are greater thanprice_meanand assign the boolean result toboolean_array. - Subset
pricesusingboolean_arrayand assign the result toabove_avg.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Find the mean
price_mean = np.mean(prices)
# Create boolean array
boolean_array = (____)
print(boolean_array)
# Select prices that are greater than average
above_avg = prices[____]
print(above_avg)