Symbolic Math with SymPy

This article shows how to solve math equations and expressions symbolically, in Python. Thanks to the Sympy library, this turns out to be an extremely easy task. However, as you will see in the following examples, the number of tools and functions provided by this library is huge. Thanks to all its features, Sympy represents … Read more

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

NumPy’s np.matmul() and the @ operator perform matrix multiplication. They compute the dot product of two arrays. For 2D arrays, it’s equivalent to matrix multiplication, while for higher dimensions, it’s a sum product over the last axis of the first array and the second-to-last of the second array. Have you ever tried to multiply two … Read more

NumPy Dot Product

Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. An important application of arrays, matrices, and vectors is the dot product. This article will teach you everything you need to know to get started! The dot product behaves differently for different input arrays. Dot Product 1D array and Scalar … Read more

[Numpy * Operator] Element-wise Multiplication in Python

NumPy is a popular Python library for data science. Numpy focuses on array, vector, and matrix computations. If you work with data, you cannot avoid NumPy. So learn it now and learn it well. In this tutorial, you’ll learn how to calculate the Hadamard Product (= element-wise multiplication) of two 1D lists, 1D arrays, or … Read more

A Guide to Pythonโ€™s pow() Function

Exponents are superscript numbers that describe how many times you want to multiply a number by itself. Calculating a value raised to the power of another value is a fundamental operation in applied mathematics such as finance, machine learning, statistics, and data science. This tutorial shows you how to do it in Python! Definition For … Read more

Recursive Power Function: Are You Stuck With This Sololearn Code?

If you learn Python with the excellent Sololearn app, you may find yourself with this code snippet: What’s the output of this code snippet? And, most importantly, how does it work? This short guide will tell you! The code creates a function that returns x^y. It leverages the important programming concept of recursion: it calls … Read more

Python Modulo

 When I studied computer science, the professors pushed us to learn the theory behind modulo operations and residual classes. But many of us lacked motivation. We could not see why calculating the remainder of the division, i.e., modulo, is such an important concept. Yet, many practical code projects later, I have gained the experience that … Read more

Python Math Domain Error (How to Fix This Stupid Bug)

You may encounter a special ValueError when working with Pythonโ€™s math module. Python raises this error when you try to do something that is not mathematically possible or mathematically defined. To understand this error, have a look at the definition of the domain: “The domain of a function is the complete set of possible values … Read more