All Questions
Tagged with vectorization numpy
32 questions
4
votes
1
answer
188
views
Finding specific promotions from two columns [closed]
I'm trying to build a function that identifies those who are promoted into a list of jobcodes, or are promoted within that list of jobcodes.
Initially I was using ...
1
vote
1
answer
709
views
Exponentially-weighted moving mean and standard deviation of an irregularly-spaced weighted time series
The following numpy/python function computes exponentially-weighted moving mean and standard deviation of an irregularly-spaced weighted time series. I want to make it faster by getting rid of the ...
3
votes
1
answer
103
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 ...
2
votes
1
answer
190
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 ...
5
votes
2
answers
207
views
Snake game from the viewpoint of the snake
I wrote a little game of Snake 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 of ...
5
votes
1
answer
231
views
Implement vectorization instead of nested loops on dataframe
I have a dataset ('sample_data.csv') of the form below:
...
4
votes
1
answer
96
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:
...
1
vote
0
answers
205
views
condensed nearest centroid classifier in numpy
This is my attempt to write a numpy-optimized version of a nearest centroid classifier to classify some images from the MNIST data set of handwritten digits. I am ...
4
votes
2
answers
1k
views
PyTorch Vectorized Implementation for Thresholding and Computing Jaccard Index
I have been trying to optimize a code snippet which finds the optimal threshold value in a n_patch * 256 * 256 probability map to get the highest Jaccard index ...
1
vote
1
answer
499
views
Vectorized N-Dimensional Random Walk in Cartesian Coordinates
I have written a random-walk routine that I hope to build upon in the future. Before doing so, I was hoping to get some critique.
I believe the implementation is correct. I noticed that many other ...
2
votes
1
answer
6k
views
Find first threshold crossing in numpy array
Given the following artificially generated data:
...
6
votes
2
answers
8k
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 ...
3
votes
0
answers
314
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 ...
1
vote
1
answer
978
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/...
6
votes
2
answers
3k
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.
...
11
votes
1
answer
348
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 ...
5
votes
2
answers
106
views
Efficient calculation of bond overlap
For a small library dealing with molecules, I have to calculate a so called connectivity table for the chemical bonds.
I assume that there is a bond between atom i and atom j, if the distance between ...
4
votes
2
answers
479
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:
...
2
votes
1
answer
1k
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
1
answer
2k
views
Generate a random discrete signal
I currently have this code to generate a discrete signal with random amplitudes, but a fixed frequency:
...
5
votes
2
answers
573
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:
...
1
vote
1
answer
166
views
Vectorizing in Python [closed]
I have the following code:
...
9
votes
2
answers
19k
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 ...
2
votes
3
answers
3k
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 ...
8
votes
1
answer
3k
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 ...
2
votes
1
answer
1k
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.
...
2
votes
1
answer
124
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 ...
3
votes
2
answers
7k
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?
<...
2
votes
2
answers
3k
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 ...
4
votes
1
answer
437
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
2
answers
493
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 ...
3
votes
1
answer
928
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 ...