# Month: August 2018

## How to Calculate the Weighted Average of a Numpy Array in Python?

NumPy’s average function computes the average of all numerical values in a NumPy array. When used without parameters, it simply calculates the numerical average of all values in the array, no matter the array’s dimensionality. For example, the expression np.average([[1,2],[2,3]]) results in the average value (1+2+2+3)/4 = 2.0. However, what if you want to calculate …

## Python Numpy 101: How to Calculate the Simple Average of a Numpy Array?

[python] import numpy as np # stock prices (3x per day) # [morning, midday, evening] solar_x = np.array( [[2, 3, 4], # day 1 [2, 2, 5]]) # day 2 print(np.average(solar_x)) [/python] What is the output of this puzzle? *Beginner Level* (solution below) Numpy is a popular Python library for data science focusing on arrays, …

## Python Numpy 101: How to Index Elements in Numpy Arrays?

Daily Data Science Puzzle [python] import numpy as np # air quality index AQI data hong_kong = np.array( [ 42, 40, 41, 43, 44, 43 ]) new_york = np.array( [ 30, 31, 29, 29, 29, 30 ]) montreal = np.array( [ 11, 11, 12, 13, 11, 12 ]) hk_mean = (hong_kong[0] + hong_kong[-1]) / 2.0 …