The Numpy Library

NumPy Broadcasting – A Simple Tutorial

Broadcasting describes how NumPy automatically brings two arrays with different shapes to a compatible shape during arithmetic operations. Generally, the smaller array is “repeated” multiple times until both arrays have the same shape. Broadcasting is memory-efficient as it doesn’t actually copy the smaller array multiple times. Here’s a minimal example: Let’s have a more gentle …

NumPy Broadcasting – A Simple Tutorial Read More »

SVM sklearn: Python Support Vector Machines Made Simple

Support Vector Machines (SVM) have gained huge popularity in recent years. The reason is their robust classification performance – even in high-dimensional spaces: SVMs even work if there are more dimensions (features) than data items. This is unusual for classification algorithms because of the curse of dimensionality – with increasing dimensionality, data becomes extremely sparse …

SVM sklearn: Python Support Vector Machines Made Simple Read More »

Python Scikit-Learn Decision Tree [Video + Blog]

Decision Trees are powerful and intuitive tools in your machine learning toolbelt. Decision trees are human-readable – in contrast to most other machine learning techniques. You can easily train a decision tree and show it to your supervisors who do not need to know anything about machine learning in order to understand how your model …

Python Scikit-Learn Decision Tree [Video + Blog] Read More »

How to Convert a Boolean Array to an Integer Array in Python?

Problem Formulation Given a NumPy array consisting of Boolean values. How to convert it to an integer array? Convert each True value to integer 1, and Convet each False value to integer 0. Here’s an example Boolean array: What you want is the following integer array: Let’s examine some methods to accomplish this easily. Method …

How to Convert a Boolean Array to an Integer Array in Python? Read More »

Division in Python

The double-frontslash // operator performs integer division and the single-frontslash / operator performs float division. An example for integer division is 40//11 = 3. An example for float division is 40/11 = 3.6363636363636362. A crucial lesson you need to master as a programmer is “division in Python”. What does it mean to divide in Python? …

Division in Python Read More »

[Tutorial] K-Means Clustering with SKLearn in One Line

If there is one clustering algorithm you need to know – whether you are a computer scientist, data scientist, or machine learning expert – it’s the K-Means algorithm. In this tutorial drawn from my book Python One-Liners, you’ll learn the general idea and when and how to use it in a single line of Python …

[Tutorial] K-Means Clustering with SKLearn in One Line Read More »

How to Convert a Tensor to a NumPy Array in TensorFlow?

There are two ways to convert a Tensor to a NumPy array: TensorFlow version 2.x — use tensor.numpy() TensorFlow version 1.x — use tensor.eval(session=tf.compat.v1.Session()) Let’s dive into these two methods in greater detail. Method 1: Explicit Tensor to NumPy Array Conversion in TensorFlow 2.x To convert a tensor t to a NumPy array in TensorFlow …

How to Convert a Tensor to a NumPy Array in TensorFlow? Read More »

16 PDF Cheat Sheets for Programmers

A couple of years ago, I fell into the habit of creating cheat sheets when exploring certain areas in the programming space. Over time, hundreds of thousands of Finxters have downloaded and used them in their own learning journeys. However, the cheat sheets are largely scattered around many different locations on the Finxter ecosystem. And …

16 PDF Cheat Sheets for Programmers Read More »

Machine Learning Linear Regression Python

Python Linear Regression with sklearn – A Helpful Illustrated Guide

💡 This tutorial will show you the most simple and straightforward way to implement linear regression in Python—by using scikit-learn’s linear regression functionality. I have written this tutorial as part of my book Python One-Liners where I present how expert coders accomplish a lot in a little bit of code. Feel free to bookmark and download …

Python Linear Regression with sklearn – A Helpful Illustrated Guide Read More »

NumPy Diff Simply Explained [Tutorial + Video]

💡 NumPy’s np.diff() function calculates the difference between subsequent values in a NumPy array. For example, np.diff([1, 2, 4]) returns the difference array [1 2]. Here is a simple example to calculate the Fibonacci number differences: This code snippet shows the most simple form of the np.diff() method: how to use it on a one-dimensional NumPy …

NumPy Diff Simply Explained [Tutorial + Video] Read More »

Selective Indexing

Conditional Indexing: How to Conditionally Select Elements in a NumPy Array?

Problem Description: 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. A feature called conditional indexing or selective indexing. …

Conditional Indexing: How to Conditionally Select Elements in a NumPy Array? Read More »