Daily Data Science Puzzle

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

You can play with the following interactive Python code to calculate the variance of a 2D array (total, row, and column variance). Here’s another practical example: What is the output of this puzzle?*Advanced Level* (solution below) Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. This puzzle introduces a …

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

How to Calculate Variance of Python NumPy Arrays?

Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. Did you already learn something new today? Let’s master the popular variance function in NumPy! Problem: How to calculate the variance of a NumPy array? Solution: To calculate the variance of a Python NumPy array x, use the function np.var(x). …

How to Calculate Variance of Python NumPy Arrays? Read More »

NumPy Diff Simply Explained [Bonus Video]

The NumPy diff function np.diff() calculates the difference between subsequent values in a NumPy array. For example, calling np.diff() on the NumPy array [1 2 4] would result in the difference array [1 2]. Here is a detailed example: This code snippet shows the most simple form of the np.diff() method: how to use it …

NumPy Diff Simply Explained [Bonus Video] Read More »

Numpy Weighted Average np.average(array, axis=0, weights=[0.1,0.1,0.8])

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 …

How to Calculate the Weighted Average of a Numpy Array in Python? Read More »

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 Calculate the Simple Average of a Numpy Array? Read More »

How to Calculate the Standard Deviation of a Numpy Array?

Daily Data Science Puzzle [python] 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))) [/python] What is the output of this puzzle? *Intermediate Level* (solution below) Numpy is a popular Python library for data science for …

How to Calculate the Standard Deviation of a Numpy Array? Read More »

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 …

A Case for Puzzle-based Learning Python Read More »

[Numpy * Operator] Element-wise Multiplication in Python

How does element-wise multiplication of two numpy arrays a and b work in Python’s Numpy library? Simply use the star operator “a * b”! Here is a code example from my new NumPy book “Coffee Break NumPy”: Can you guess the output of this puzzle?*Advanced Level* (see solution below) NumPy is a popular Python library …

[Numpy * Operator] Element-wise Multiplication in Python Read More »

Is This an Average Puzzle? Yes!

Daily Data Science Puzzle [python] import numpy as np # Goals in five matches goals_brazil = np.array( [1,2,3,1,2]) goals_germany = np.array( [1,0,1,2,0]) br = np.average(goals_brazil) ge = np.average(goals_germany) print(br>ge) [/python] What is the output of this puzzle? *Beginner Level* Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. This …

Is This an Average Puzzle? Yes! Read More »