# 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

74 questions
Filter by
Sorted by
Tagged with
150 views

### Vectorizing in Python [closed]

I have the following code: ...
16k views

### Efficient element-wise function computation in Python

I have the following optimization problem: Given two np.arrays X,Y and a function K I ...
780 views

### Optimization of multiple arrays for filtering

My app will be running on an iPad with A7. I pass in 3 JSON arrays and right now do some simple filtering, in the future the operation will be much more complicated. I realize the ...
1k views

### Scaling and incrementing non-zero elements of a NumPy matrix

I have a NumPy matrix C and want create a copy of it cPrime, which has some operation of the original matrix to all non-zero ...
1k views

### Vectorized numpy version of arange with multiple start stop

Given a single start and stop, numpy.arange is a good solution for building a NumPy array of evenly spaced values. However, given an array of start and an array of ...
817 views

### NumPy eliminate double loop [closed]

How can I vectorize this code snippet and eliminate this double loop? Even with "only" 1001 elements in a this takes almost 30s. ...
406 views

### Optimize matlab triple for loop

I have a large matrix samples, I want to make another matrix sampleProb which is the same size, but modified as below: ...
109 views

### Modeling and plotting neuron responses

I want to assign the row of a matrix the return value of a function, but the only way I can figure out how to do this is with a for-loop. I'm assuming this is bad ...
5k views

### Generate random unit vectors around circle

I'm trying to generate a bunch of uniformly distributed unit vectors around the unit circle. Here's my code, which is working, but unfortunately I have a for-loop. How do I get rid of this for-loop? <...
98 views

### Vectorization for temperature simulation

I'm new to Matlab and I would like to know tips in order to reduce the processing time of such program. The scheme of the actual code is very similar to typical C++ code and I would like to vectorize ...
117 views

### Speeding up loop-rich Matlab function to calculate temperature distribution

I would like to speed up this function as much as possible in Matlab. This is part of a bigger simulation project, and as it is one of the most called functions within the simulation, this is crucial. ...
271 views

### Improving Matlab function within big simulation

I have a very big Matlab simulation project in my hands, which I wanted to optimize, since I'm running it many times to tune parameters and the like. Using Matlab's ...
74 views

### Fast counting of interactions between groups given users interactions and groups assignments

Given: An array c that contains the group assignment of every user (c[i]=4 indicates that user i belongs to group 4) A matrix ...
138 views

### Vector comparison inside for-loop

The following code finds no-rain periods in a time series that were preceded by rain over a threshold (e.g. 10mm in 2 days [k=48]). ...
2k views

### Extracting maximum values from each of the subsets of an array

Problem description: I have a numpy array cps from which I want to extract the maximum value in each of the subsets of the array (a subset is defined as non-zero ...
350 views

### Bernoulli trials using a condition in a vectorized operation

I was wondering how to vectorize the following code instead of using the for-loop and still be able to check for a condition. ...
147 views

### Catalogue manipulation

I have a catalogue of 56000 objects and I want to replace some columns with new values for instance replace NaN with -99 and <...
79 views

### Determining the value of a position on an array based on its nearest datapoint known value

I was wondering what would be the efficient way to determine the value of a position on an array based on its nearest datapoint known value in Python? Problem description: There are datapoints ...
4k views

### Run length encoding of vectors in MATLAB: looped version and vectorized version

A project I'm working on requires something akin to run length encoding on a vector in matlab. The data is in the form of a numeric vector, and the output is in the form of two vectors, ...
701 views

### Implementation of MATLAB's im2col

The function im2col in MATLAB is very useful to vectorize Patch based Image Processing algorithms. The problem is the function isn't optimized and doesn't use C ...
226 views

### Calculating mesh centers runs very slowly

I have a piece of code that is used to calculate the cell centers in a rectangular mesh. The mesh size is pretty large (650 columns by 1150 rows). The code runs very slowly. I was wondering if I could ...
785 views

### Merging overlapping/intersecting string vectors

I am trying to merge overlapping/intersecting sets given as a list of string vectors below in R (my actual data set has thousands of such sets). The overlap/intersection is based on the ...