You already know numpy’s average function, don’t you? This article goes a step further and shows you how to calculate the weighted average of a numpy array. You can pass four arguments to the numpy average function: The numpy array which can be multi-dimensional.(Optional) The axis along which you want to average. If you don’t specify the argument, the averaging …

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

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)) What is the output of this puzzle? *Beginner Level* (solution below) Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. This puzzle introduces the …

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

Daily Data Science Puzzle 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 ny_mean = (new_york[1] + new_york[-3]) / …

## How to Calculate the Standard Deviation of a Numpy Array?

Daily Data Science Puzzle import numpy as np temp_sensor = np.array( [ 18, 22, 22, 18 ]) mean = np.mean(temp_sensor) std = np.std(temp_sensor) print(str(int(mean – std)) + "-" + str(int(mean + std))) What is the output of this puzzle? *Intermediate Level* (solution below) Numpy is a popular Python library for data science for array, vector, and matrix computations. This puzzle …

## How to Calculate the Standard Deviation in Numpy?

Daily Data Science Puzzle import numpy as np # daily stock prices # [open, close] google = np.array( [[1239, 1258], # day 1 [1262, 1248], # day 2 [1181, 1205]]) # day 3 # standard deviation y = np.std(google, axis=1) print(y[2] == max(y)) What is the output of this puzzle? *Advanced Level* (solution below) Numpy is a popular Python library …

## Python Numpy 101: How to Calculate the Row Variance of a Numpy 2D Array?

Daily Data Science Puzzle import numpy as np # stock prices (3x per day) # [morning, midday, evening] APPLE = np.array( [[50,60,55], # day 1 [60,60,65]]) # day 2 # midday variance y = np.var(APPLE, axis=0)[1] print(int(y)) What is the output of this puzzle? *Advanced Level* (solution below) Numpy is a popular Python library for data science focusing on arrays, …

## A Case for Puzzle-based Learning Python

Overcome the Knowledge Gap The great teacher Sokrates delivered complex knowledge by asking a sequence of questions. Each question was building on answers to previous questions provided by the student. This more than 2400 year old teaching technique is still in wide-spread use today. A good teacher opens a gap between their’s and the learner’s knowledge. This knowledge gap makes …

## Python Numpy 101: How to Calculate Variance of Numpy Arrays?

Daily Data Science Puzzle import numpy as np # Goals in five matches goals_croatia = np.array( [0,2,2,0,2]) goals_france = np.array( [1,0,1,1,0]) c = np.var(goals_croatia) f = np.var(goals_france) print(c>f) What is the output of this puzzle? *Intermediate Level* (solution below) Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. This puzzle introduces a new feature …

## How to index 1D numpy arrays?

Daily Data Science Puzzle import numpy as np # The fibonacci series F = np.array([0, 1, 1, 2, 3, 5, 8]) F[::3] = 0 print(sum(F[:4])) What is the output of this puzzle? *Intermediate Level* Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. This puzzle demonstrates indexing in numpy arrays. You most likely know …

## Take a Guess: What is the Meaning of the Numpy *-Operator, Matrix Multiplication or Element-wise Multiplication?

Daily Data Science Puzzle import numpy as np # salary in ($1000) [2015, 2016, 2017] dataScientist = [133, 132, 137] productManager = [127, 140, 145] designer = [118, 118, 127] softwareEngineer = [129, 131, 137] # Salary matrix S = np.array([dataScientist, productManager, designer, softwareEngineer]) # Salary increase matrix I = np.array([[1.1, 1.2, 1.3], [1.0, 1.0, 1.0], [0.9, 0.8, 0.7], [1.1, …