↓ Skip to main content

Blog

2026

Optimization with SciPy

Optimization with SciPy

·6536 words·31 mins
Differentiating and setting the result to zero solves textbook optimization. With several variables, constraints, or a function without a tractable derivative, that calculation breaks down. We will see minimize, SLSQP and bounds from scipy.optimize, local minima, and global search with differential_evolution.
Numerical Integration with SciPy

Numerical Integration with SciPy

The Gaussian function has no elementary antiderivative, and that is a theorem of Liouville. When the antiderivative does not exist, or all you have is a table of measurements, the way forward is numerical: quad, trapezoid and Simpson, from scipy.integrate, with the care each one demands.
Curve Fitting with NumPy

Curve Fitting with NumPy

·5574 words·27 mins
Experimental data rarely falls on a curve. We will see how NumPy fits polynomials to noisy data, what SymPy cannot do, why extrapolating is dangerous, and why Runge’s phenomenon comes from equally spaced nodes, not from high degree.
Polynomials with NumPy

Polynomials with NumPy

·3534 words·17 mins
Stored in float64, the coefficients of Wilkinson’s polynomial no longer return the roots 1 to 20: two of them become a complex pair. Before getting there, we look at roots, derivatives, integrals and division with numpy.polynomial, and at the coefficient-order trap.
Planar Graphs: When Crossing Is Unavoidable

Planar Graphs: When Crossing Is Unavoidable

·4243 words·21 mins
Try to connect three houses to gas, water, and electricity without crossing lines: it is impossible. We will see why, with Euler’s Formula, the proof that the three-houses graph and the complete graph on five vertices are not planar, Kuratowski’s Theorem, and the coloring of planar graphs, from six colors down to four.
Eulerian and Hamiltonian Graphs

Eulerian and Hamiltonian Graphs

·6397 words·31 mins
Traversing each edge exactly once is easy to decide: just look at the parity of the degrees (Euler’s Theorem). Deciding whether we can visit each vertex exactly once is NP-complete. We will see both problems, the theorems of Dirac and Ore, and the Traveling Salesman, from Held-Karp to Christofides.
The Binomial Theorem: Expanding (a+b)^n

The Binomial Theorem: Expanding (a+b)^n

·1966 words·10 mins
What is the coefficient of a term in the expansion of a binomial raised to the tenth power? The binomial theorem answers in one line, with the coefficients from Pascal’s triangle. We will see the theorem and its proof by induction, the general term formula, and the identities that come from special cases.
Sets in Python: set, frozenset, and Operations

Sets in Python: set, frozenset, and Operations

·2753 words·13 mins
Testing whether an element is in a set takes constant time on average, while in a list the time grows with its size. We will see how set theory becomes Python code: set and frozenset, comprehension, membership and inclusion, union, intersection and difference, hashing, and practical applications.
Venn Diagrams and Set Operations

Venn Diagrams and Set Operations

·3803 words·18 mins
Union, intersection, difference, and complement are the basic operations on sets, and they show up in SQL as UNION, INTERSECT, and EXCEPT. We see each one in Venn diagrams, along with De Morgan’s laws, distributivity, and the difference between a Venn diagram and an Euler diagram.

2023

NumPy broadcasting and vector quantization

NumPy broadcasting and vector quantization

·3913 words·19 mins
We learn in math that there are rules for adding or multiplying matrices. But in computational math problems we sometimes have matrices or vectors that we would like to add or multiply and that do not meet the requirements. In this article we will see how the NumPy broadcasting concept is useful in these contexts and how it relates to vector quantization.
So, What Is NumPy's reshape?

So, What Is NumPy's reshape?

·2409 words·12 mins
If you are venturing into data science, you have most likely seen a reshape in some code. Maybe with a mysterious value of -1 in one of the positions, as in reshape(-1, 1). But what does that mean? Why do we sometimes need to transform our data to use model methods in Scikit-Learn? That is what we will see in this article.

2022

Infinite Series - Calculus with Python and SymPy

Infinite Series - Calculus with Python and SymPy

·8151 words·39 mins
A good part of the study of calculus is devoted to what are called infinite series. But what, exactly, are infinite series? And how are they related to the paradox of Achilles and the tortoise, one of the so-called paradoxes of Zeno of Elea, the Greek philosopher? What is the connection with quantum mechanics and the uncertainty principle? And where does Python come in? That is what we will find out in this article.
Integrals - Calculus with Python and SymPy

Integrals - Calculus with Python and SymPy

We have already written here on the site about the concepts of limit and derivative and how we can do the related computations with Python. Continuing our journey through calculus, in this article we will see how to work with integrals using SymPy and SciPy, Python packages. Along the way, we will pick up some notions of numerical methods.
Calculus with Python and SymPy: limits

Calculus with Python and SymPy: limits

·2289 words·11 mins
The concept of a limit is the most important one in the study of calculus. Many other concepts and ideas are built on the definition of a limit. In this article, we will see how to find the limit of functions using SymPy and how this package can be a teaching aid in the study of calculus.
How to Install Linux Mint

How to Install Linux Mint

·191 words·1 min
Linux Mint is a distribution based on Ubuntu whose main desktop environment is Cinnamon. Its look is more familiar to people migrating from Windows, and it meets the needs of all kinds of users.

2021

Logic for Programmers

Logic for Programmers

·4174 words·20 mins
In programming, the word “logic” can refer to the process of designing an algorithm, to the conditional structures of the language, or to logical operators such as AND and OR. In the last two cases, we are within what is called mathematical logic.
Plots with SymPy and Matplotlib

Plots with SymPy and Matplotlib

·3611 words·18 mins
In this article we will see how to make plots with SymPy and Matplotlib. When people talk about SymPy, we usually focus on solving mathematical problems. But many forget that the library has some basic features for building plots, which we will see in this article.
Git and GitHub: The Definitive Collaboration Guide

Git and GitHub: The Definitive Collaboration Guide

·4495 words·22 mins
Git can be a somewhat scary tool for beginners because of its large number of commands and possibilities. In this article, we demystify the main aspects of Git so that you can collaborate on any project. The famous workflow of forks and pull requests, popularized by GitHub, is covered.
ENEM: The Killer Brick Problem

ENEM: The Killer Brick Problem

Is it possible to study for the college entrance exam and still learn Python? Of course! And that is one of the goals of the Brazilian Exam Problems category on this site. In it, we use computational tools to analyze and expand problems from the ENEM, Brazil’s national high school exam. In today’s article, we analyze a problem from the 2019 exam. And, along the way, we learn to make 3D and 4D(?!) plots with Matplotlib. All because of a killer brick.

2020

Studying Our Atmosphere with Python

Studying Our Atmosphere with Python

Colorless, made of invisible constituents, and odorless (we hope!). We often forget that we are surrounded by the gases that make up our atmosphere. In this article, we will see how to easily get a list of the main constituents of air with Python and web scraping. We will also do some calculations, such as density and mean molar mass, and, of course, present everything in spectacular plots.