# Month: February 2019

## Static and Dynamic Attributes in Python – What’s the Difference?

Let’s play with some code first to answer this question: You can also watch my explainer video while you read through the remaining article: By studying this question, you will improve your understanding of not only the fine details but also of the whole picture “object-oriented programming”. So, let’s start by answering the two questions: …

## 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 …

## Python Ziiiiiiip! [A helpful guide]

Many coders struggle with understanding the zip function. Let’s fix this for you. The zip function takes a number of iterables and aggregates them to a single one by combining the i-th values of each iterable into a tuple for every i. (An iter-able is an object that contains multiple elements over which you can …

## Python Linear Regression in One Line [A Helpful Illustrated Guide]

This one-liner uses two Python libraries: NumPy and scikit-learn. The former is the de-facto standard library for numerical computations (e.g. matrix operations). The latter is the most comprehensive library for machine learning which implements hundreds of machine learning algorithms and techniques. You may ask: “why are you using libraries in a Python one-liner? Isn’t this …

## The Ultimate Guide to Python Sets – with Harry Potter Examples

This article gives you everything you need to know about sets in Python. To make it a bit more fun, I have used Harry Potter examples throughout the article. ​Table of Contents What is a Set in Python?How to ​Create a Set?Can a ​Set ​Have ​Multiple ​Data ​Types?What ​Are ​Real-​World Examples of ​Sets?[Overview] What ​Are the …

## The Reduce Function in Python 3: Simply Explained

The reduce function in Python reduces a sequence of elements to a single element by repeatedly applying a specified function that takes two sequence elements and merges them to a single element. By repeating this behavior, ultimately, only a single value will remain — the sequence is reduced to a single element. Here is an …

## How to Conditionally Select Elements in a Numpy Array?

You have a Numpy array. You want to select specific elements from the array. But neither slicing nor indexing seem to solve your problem. What can you do? In this short tutorial, I show you how to select specific Numpy array elements via boolean matrices. You can even use conditions to select elements that fall …

## How to 10x Your Coding Productivity

Learn Less Random Stuff A loyal reader of my Python email course, Lee, asked the following question: “One of the first things I learned was that I needed to learn how to use the Powershell in addition to Python so I could write the programs in the IDE, then run them in the shell. […] …

## How to Calculate the Levenshtein Distance in Python?

After reading this article, you will know exactly how to calculate the edit distance in Python. Learning requires opening your knowledge gap first. So let’s do this. What is the output of the following Python puzzle showing you a concise code snippet to calculate the edit distance in Python? (source) Python Source Code Now, this …