Vectorization refers to a programming paradigm where functions operate on whole arrays in one go. This affords benefits in terms of function calls, memory access, parallelization and code expressiveness. Some programming languages, such as MATLAB, are optimised to give the best performance when ...

learn more… | top users | synonyms

7
votes
3answers
180 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 ...
7
votes
1answer
115 views

Matlab Computer Vision

The code below takes a video as input (a drop onto a fabric surface) and I want it to return the area of the drop. Currently the code works, but I'm no Matlab expert, and wrote it entirely through ...
7
votes
0answers
78 views

Vectorizing the product of an array of complex numbers

I am trying to write fast/optimal code to vectorize the product of an array of complex numbers. In simple C this would be: ...
6
votes
1answer
808 views

Remove duplicates in list of lists where an item in each list is ignored when determining duplicity

I have lines_list_copy of the form: [['a1', 'b1', 'c1', 'd1', 'e1'], ['a2', 'b2', 'c2', 'd2', 'e2'], ... ] I needed to ...
6
votes
1answer
343 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 ...
5
votes
2answers
143 views

Jacobian product

Do you have in mind a way to compute the following sum $$R_{i,j,k} = \sum_{l=0}^{2} J_{i,j,l+3k} v_{i,j,l}$$ obviously in a vectorised fashion? This may sound like an equivalent of: ...
5
votes
1answer
121 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]). ...
5
votes
2answers
84 views

Extract the largest value for each day from a matrix

I have a matrix in which the right-most elements are repeated YYYYMMDD dates in descending order, for example: ...
5
votes
1answer
141 views

Evaluating a series of Legendre polynomials

The following function represents the electrostatic potential, in spherical coordinates, due to a ring of charge \$q=1\$ and radius \$R=1\$, placed in the plane \$x\$-\$y\$: $$\phi(r,\theta) = \sum_{...
5
votes
2answers
2k 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 ...
5
votes
1answer
91 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 ...
5
votes
1answer
115 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 <...
4
votes
1answer
83 views

Biometric matching score calculator

I'm working on a biometric matching system and I would like to have few suggestions regarding vectorizing the following code: ...
4
votes
1answer
187 views

Rolling regressions in R

I want to run rolling regressions over each group and store the coefficient. The following works, but it's slow, since I have too many series and I want to run too many regressions for each group. ...
4
votes
1answer
300 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 ...
4
votes
1answer
330 views

Vectorize Matlab sum

I have the following Matlab function: function [res] = a3_funct(x) res = 0; for i = 1:size(x,1) res = res + abs(x(i))^(i+1); end end It's ...
4
votes
2answers
75 views

Vectorizing a pixel-averaging operation in Numpy

I am reading from a file containing some segments (irregular parcels of the image) and trying to average the entire segment to have one pixel value. This is the code I use: ...
4
votes
1answer
64 views

Vectorizing Two Sample Kolmogorov-Smirnov test

I'm implementing the Two-sample Kolmogorov-Smirnov test in MATLAB. I must admit I know very little of formal statistics and was simply trying to implement the description in wikipedia's page. Right ...
4
votes
1answer
220 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. ...
3
votes
1answer
392 views

Using Gibbs sampling to segment an image

I have been reading some NumPy guides but can't seem to figure it out. My TA told me I should be able to speed up my code by using a NumPy array instead of a for ...
3
votes
1answer
57 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 ...
3
votes
2answers
74 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 ...
3
votes
2answers
93 views

Weighted dice with n faces

Here you find some code that returns the value of a multivariate Bernoulli density function - for a dice with n faces, where each face has its weight (weight must be positive reals, not necessarily ...
3
votes
1answer
51 views

Updating an inventory with R using apply functions

I have created an inventory that works via QR codes. Briefly: the QR code codes for an email with the book/student checking it out. The email is downloaded into R using the gmailR package (code not ...
3
votes
1answer
189 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 ...
3
votes
1answer
100 views

NumPy eliminate double loop

How can I vectorize this code snippet and eliminate this double loop? Even with "only" 1001 elements in a this takes almost 30s. ...
3
votes
1answer
3k 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, ...
3
votes
2answers
120 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 ...
2
votes
1answer
65 views

Generate a random discrete signal

I currently have this code to generate a discrete signal with random amplitudes, but a fixed frequency: ...
2
votes
1answer
34 views

Find signal's maximum peak in window

I have a 9-dimensional signal (as a csv from this Gist) that looks like this: A signal peaks every 30 steps. I want to get the maximum values of the peaks in that ...
2
votes
1answer
79 views

Vectorizing a polar coordinate conversion loop in a fingerprint-matching process

I am working on a fingerprint matching technique and it takes a lot of computation time to obtain the result. I am trying to implement the matching process given in A Minutia Matching Algorithm in ...
2
votes
1answer
65 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 ...
2
votes
2answers
1k 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 ...
2
votes
1answer
103 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. ...
1
vote
1answer
117 views

Horizontally concatenating the entries of two matrices, and padding with NaNs

I have two matrices a and b that have, on each line, some values (null or not) and then a bunch of zeros at the end. I want to ...
1
vote
2answers
2k 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? <...
1
vote
1answer
225 views

Pattern recognition and machine learning - Bernoulli mixture model

I have been reading the book Pattern Recognition and Machine Learning (Bishop) for a while, and recently I came across this figure, which was created using Bernoulli mixture model on the MNIST dataset:...
1
vote
1answer
117 views

Merging two square matrices

I would like to optimize a snippet of code, which uses a multiple nested if statements. I am looking for a formula to make it as a combination of multiple arrays ...
1
vote
1answer
92 views

Vectorizing in Python

I have the following code: ...
1
vote
2answers
93 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 ...
1
vote
1answer
204 views

Operating multiple columns of one pandas DataFrame using data from another

I have a DataFrame of data from a survey that was repeated over several years, asking people about their income and how much money they had in savings. For simplicity, let's pretend it looks like this:...
1
vote
1answer
275 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: ...
1
vote
0answers
35 views

Forecasting function using auto.arima for 15 samples of data

I have a workbook with data sampled. i have multiple samples based on date range. one sample starts from january, where other can start from february and so on. I need to build forecasting function ...
1
vote
0answers
348 views

Efficient C Code Alternative to 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 ...
0
votes
0answers
37 views

Multiplication of n-dimensional arrays with broadcasting

For explaintion of multiplication with broadcasting, see here. Problem: The nested loop of the simplified code is not vectorized. How to fix the simplified code so that its nested loop would ...