Jason Brownlee's Blog, page 20
May 28, 2023
Numpy Parallel Vector Distance Calculation
You can calculate vector distances in parallel by using SciPy distance functions and threads. In this tutorial, you will discover how to calculate vector distances between numpy arrays in parallel using threads. Let’s get started. Need Parallel Vector Distance Calculation A vector is an array of numbers. A common operation with vectors is to calculate […]
Published on May 28, 2023 12:00
May 25, 2023
Parallel Numpy Matrix Math Functions
You can calculate mathematical functions on matrices in numpy in parallel using Python threads. This can be achieved because most numpy math functions release the global interpreter lock, allowing Python threads that call numpy math functions to run in parallel. In this tutorial, you will discover how to calculate mathematical numpy functions on matrices in […]
Published on May 25, 2023 12:00
May 23, 2023
Parallel Numpy Array Fill (up to 3x faster)
You can fill a Numpy array in parallel using Python threads. Numpy will release the global interpreter lock (GIL) when calling a fill function, allowing Python threads to run in parallel and populate different sub-arrays of a large shared array. This can offer up to a 3x speed-up, depending on the number of CPU cores […]
Published on May 23, 2023 12:00
May 21, 2023
NumPy Multithreaded Element-Wise Matrix Arithmetic
You can perform element-wise matrix math functions in parallel in numpy using Python threads. This can offer a 1.3x speed improvement over the single-threaded version of operations like element-wise matrix addition, subtraction, division, and multiplication. In this tutorial, you will discover how to perform multithreaded element-wise matrix math functions with numpy. Let’s get started. Element-Wise […]
Published on May 21, 2023 12:00
May 18, 2023
Parallel NumPy Vector Math with Threads
You can use threads to apply a math function to each item in a numpy vector. Most numpy math functions execute C-code and release the Global Interpreter Lock (GIL). This means they can be executed in parallel using Python threads, offering some speed-up. In this tutorial, you will discover how to parallelize numpy math functions […]
Published on May 18, 2023 12:00
May 16, 2023
Parallel NumPy Vector Math with Multiprocessing
You can use multiprocessing to apply a math function to each item in a numpy vector. Although this is straightforward to implement, it is likely to result in worse performance compared to the sequential version. As such, it is generally not recommended to use multiprocessing to parallelize math operations on vectors. In this tutorial, you […]
Published on May 16, 2023 12:00
May 14, 2023
Numpy Parallel Random Numbers (up to 4x faster)
You can create and populate a vector of random numbers in parallel using Python threads. this can offer a speed-up from 1.81x to 4.05x compared to the single-threaded version, depending on the approach chosen. In this tutorial, you will discover how to create a numpy vector of random numbers in parallel using threads. Let’s get […]
Published on May 14, 2023 12:00
May 11, 2023
Numpy Parallel Random Numbers with Multiprocessing (up to 28x slower)
You can create and populate a NumPy vector of random numbers in parallel using Python multiprocessing. Although possible, this is not recommended. Using multiprocessing to generate random numbers in parallel can offer a SLOW DOWN from 8.43x to 28.37x compared to the single-process version, depending on the approach chosen. This is a good exercise to […]
Published on May 11, 2023 12:00
May 9, 2023
NumPy vs the Global Interpreter Lock (GIL)
You can parallelize numpy tasks with threads in Python because most numpy functions release the global interpreter lock or GIL. In this tutorial, you will discover that most numpy array functions will release the global interpreter lock. Let’s get started. Numpy and the Global Interpreter Lock NumPy is an array library in Python. Data from […]
Published on May 09, 2023 12:00
May 7, 2023
Speed-Up NumPy With Threads in Python (up to 3.41x faster)
You can combine BLAS threads with threading in NumPy programs. Maximizing these types of parallelism can help you fully utilize your CPU cores for a given application and achieve a speed-up compared to not using any or only one level of parallelism. It can also be tricky as sometimes combining threading with NumPy BLAS threads […]
Published on May 07, 2023 12:00


