Math

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?

Problem Formulation: How to calculate the weighted average of the elements in a NumPy array? Definition weighted average: Each array element has an associated weight. The weighted average is the sum of all array elements, properly weighted, divided by the sum of all weights. Here’s the problem exemplified: Quick solution: Before we discuss the solution …

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

How to Calculate the Average of a NumPy 2D Array?

NumPy is a popular Python library for data science focusing on arrays, vectors, and matrices. This article introduces the np.average() function from the NumPy library. When applied to a 1D array, this function returns the average of the array values. When applied to a 2D array, NumPy simply flattens the array. The result is the …

How to Calculate the Average of a NumPy 2D Array? Read More »

Python round() — A Simple Guide with Video

Python’s built-in round() function takes two input arguments: a number and an optional precision in decimal digits. It rounds the number to the given precision and returns the result. The return value has the same type as the input number—or integer if the precision argument is omitted. Per default, the precision is set to 0 …

Python round() — A Simple Guide with Video Read More »

How to Calculate the Standard Deviation in NumPy?

Problem Formulation: How to calculate the standard deviation in NumPy? Differentiations: There are many different variants of this problem: Calculate the standard deviation of a 1D array Calculate the standard deviation of a 2D array Calculate the standard deviation of a 3D array Then you can also calculate the standard deviation along an axis: Calculate …

How to Calculate the Standard Deviation in NumPy? Read More »

How to Calculate Percentiles in Python

This article deals with calculating percentiles. Percentiles are statistical indicators that are used to describe specific portions of a sample population. The following sections will explain what percentiles are, what they are used for and how to calculate them, using Python. As you will see, Python allows solving this problem in multiple ways, either by …

How to Calculate Percentiles in Python Read More »

Symbolic Math with SymPy: Advanced Functions and Plots

This article will cover some advanced mathematical functions provided by the Sympy library. If you still have not read the first introductory article to Sympy, you can check it out here. Since most of the basic functions, like the ones for initiating a Sympy session on your terminal or for defining a function/variable, will not …

Symbolic Math with SymPy: Advanced Functions and Plots Read More »

NumPy Matrix Multiplication — np.matmul() and @ [Ultimate Guide]

Have you ever tried to multiply two NumPy arrays together and got a result you didn’t expect? NumPy’s multiplication functions can be confusing. In this article, we’ll explain everything you need to know about matrix multiplication in NumPy. Watch the video where I go over the article in detail: To perform matrix multiplication between 2 …

NumPy Matrix Multiplication — np.matmul() and @ [Ultimate Guide] Read More »