# Questions tagged [vectorization]

Vectorization refers to a programming paradigm where functions operate on whole arrays in one go. Use this tag if your code contains vectorized operations

95 questions
Filter by
Sorted by
Tagged with
11 views

### Vectorizing a working custom similarity function further using numpy

I am new to python, and even more new to vectorization. I have attempted to vectorize a custom similarity function that should return a matrix of pairwise similarities between each row in an input ...
1k views

### My blit function for my own graphics library

Here is a blit function for a graphics library I made. I've built a small graphics library that uses an palette-indexed spritesheet to hold all of the game's sprites. The blit function copies parts of ...
87 views

### Computing the angle between two vectors (vectorized) for small angles and with few copies

I am implementing a function that computes the angle between two vectors when given two n-dimensional arrays and an axis along which to operate. I want to do this with as few copies as possible, and ...
40 views

### Correcting coordinates of an image with polynomial root in python

I want to optimize this for loop for correcting coordinates of an image, it takes too long which is not suited for my system. I have done some profiling, the numpy roots is taking most of the time (...
74 views

### Faster Tridiagonal Matrix Multiplication

I have a function that I've been trying to make faster that computes $XA + B$, where $A \in \mathbb{R}^{n \times n}$ is a tridiagonal matrix, and $X, B \in \mathbb{R}^{m \times n}$. In the code, ...
49 views

### Snake from the viewpoint of the snake

I wrote a little game of snake that where you can see the field in which the snake moves fixed and you can also see the "viewpoint" of the snake, which is basically calculating the positions ...
40 views

### optimize binary classification method for speed

I have the following code for determining TP, TN, FP and FN values for binary classification given two sparse vectors as input (using the sparse library): ...
62 views

### Speed-up anomaly detection for pandas dataframes with vectorized operations

Motivation: I very often face a task where I need to check that dataframe's values are correct or not. Based on it I can create another dataframe with True/False values which are based on the first ...
77 views

### Vectorized numpy co-occurrence matrix generation

Update The implementation did not consider multiple occurrences of a same word, and self word occurrences. For instance when stride=2 and the word at the position is ...
121 views

### Implement vectorization instead of nested loops on dataframe

I have a dataset ('sample_data.csv') of the form below: ...
75 views

### Can this numpy code be vectorized?

I've written the following function to produce n realizations of a CIR process for a given set of parameters: ...
122 views

### C# Generic high performance vectorized math operations

I'm writing a library which simplifies the usage of intrinsics in C#. It's a generic library which supports all numeric types. The goal of this library is to perform these operations at the highest ...
106 views

### Vectorized crosstabulation in Python for two arrays with two categories each

I have two Python lists, label and presence. I want to do cross-tabulation and get the count for each block out of four, such as ...
178 views

### N-Body Optimization

I've created a serial C++ code for gravitational N-Body calculation. Because I expect to have upwards of 8-71 sparse bodies (ie, where Barnes-Hut is not necessarily practical) and running for long ...
41 views

### Vectorize a function that, once per row, updates multiple rows in data.table

Requirements I have a table of the different diagnoses a patient has received, with the date the diagnosis was first recorded. It so happens that in medicine, diagnoses are recorded as codes from a ...
33 views

### Vectorization of Mersenne Twister? [closed]

Ahoy friends. Right now i'm selling a huge amount of HDDs and usually i used DBAN or nwipe to perform this actions. Unfortunately the PRNG Mersenne Twister is quite slow, so i get a throughput of ...
95 views

### Efficiently shift elements right by one in an __mm256 vector [closed]

The code below correctly shifts v256f_stats by one and puts the results into v256f_x3. This is then used to get the delta ...
94 views

### Custom Model intended to be used for Curve Fitting. Vectorization vs For Loop and jit numba capabilities

I am new to community and please pardon me if I didn't provide information as intended. This code is supposed to be creating a custom model which will be used with ...
410 views

### AVX Vectorized Multi-threaded Mandelbrot Renderer

I wrote a Mandelbrot renderer in C++ that uses AVX intrinsics to calculate 8 pixels per thread in parallel. It can compute 1080p frames with 256 max iterations in about 40 milliseconds on a 2 core 4 ...
108 views

234 views

### Optimizations of C Code - Bilateral Filter

I'm working on a nice approximation for the Bilateral Filter. I have a working code which runs pretty fast yet still I think much can be improved. The code (C Code,...
76 views

### Generic pixel class to seamlessly alpha-blend and convert between different pixel structure layouts

Does what it says in the title. I just finished this and wanted to share with someone. Looking for possible optimizations, bugs (most of it is tested to work) or any constructive criticism. ...
3k views

### Find first threshold crossing in numpy array

Given the following artificially generated data: ...
382 views

### Vectorizing a complex nested for loop in R (running models on different subsets of a data set, subsetting the data differently for each loop)

This is my first time posting so hopefully I manage to get my question across in a clear and concise manner. I'm not sure this is the right place but someone on StackOverflow suggested I ask here. I ...
65 views

### Determining whether a list of pathways and its genes are all included in another list

I am evaluating if a list of pathways and its genes has pathways included in another pathways. So the way I thought about it is to create a function that does just a single comparison. ...
84 views

### Find the minimum value that data could have had before it was rounded

I have this function in R: ...
70 views

### 1D data classification

This R code separates the values in rData. They are classified according to the class in rClass. To do that, ...
7k views

### Compute a numerical derivative

Since I could not get numpy.gradient() to compute a derivative successfully, I wrote a script to compute it manually. Running the script below will output a plot of ...
186 views

### Merging bin-data via a bin count threshold

When performing a chi-squared test, one takes the square of the differences of the expected counts per bin and observed counts per bin, and divides these per-bin differences by the expected counts per ...
80 views

### vectorize 2D gradient with spatially varying bins

The following code takes in some values ssh and solves the equations for the geostrophic motion (slide 8 here). The main part of the code is the computation of the ...
654 views

### Normalise list of N dimensional numpy arrays

I have a list of N dimensional NumPy arrays. num_vecs = 10 dims = 2 vecs = np.random.normal(size=(num_vecs, dims)) I want to normalize them, so the magnitude/...
2k views

### Remove outliers from a point cloud

This function accepts a cloud of points, and returns those points that are within delta distance of the average (mean) position. ...
2k views

### Converting Array of Floats to UINT8 (char) or UINT16 (unsigned short) Using SSE4

The problem is given image in 32 Bit Floating Point Format (float) how to convert it to UINT8 (char) or UNIT16 (...
81 views

### Extracting data from meshgrid output

I am trying to extract data from meshgrid output where zCs is 1000 x 1000 matrix of z values which is produced from meshgrid of s using bin2mat. s is a struct which has x, y, z data. res is 1000. ...
60 views

### Function that fills a time series row-by-row by using the values in the row before

Summary: performance issue with for-loop, vectorization possible? I am processing a time series of securities price data, stored in a pandas dataframe df_buy_sell. ...
874 views

### Implementation of linear regression in Python

I wrote an implementation for multivariate linear regression in Python, for data in this link: http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv My main focus is to avoid loops as much as possible ...
1k views

### Vectorized and Multi Threaded Image Convolution

I created code for Image Convolution. The code is in my Image Convolution GitHub Repository. It includes the case for arbitrary Image Convolution and for Separable Kernel Convolution. The code is a ...
251 views

### Calculate the closest point to many hyperbolic paraboloids

In this question I asked for a way to compute the closest projected point to a hyperbolic paraboloid using python. Using the iterative approximation answer, I'm able to use the code below to ...