Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
Gage's user avatar
  • 41
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 ...
yuri kilochek's user avatar
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 ...
dddxxx's user avatar
  • 131
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 ...
FirefoxMetzger's user avatar
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 ...
Javier Camacho's user avatar
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: ...
rfguy's user avatar
  • 51
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: ...
John Smith's user avatar
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 ...
Grayscale's user avatar
  • 127
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 ...
yiping's user avatar
  • 73
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 ...
user avatar
2 votes
1 answer
6k views

Find first threshold crossing in numpy array

Given the following artificially generated data: ...
Seanny123's user avatar
  • 1,535
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 ...
user avatar
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 ...
user avatar
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/...
Seanny123's user avatar
  • 1,535
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. ...
adrienlucca.net's user avatar
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 ...
Fnord's user avatar
  • 383
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 ...
mcocdawc's user avatar
  • 944
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: ...
shaunakde's user avatar
  • 245
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 ...
Seanny123's user avatar
  • 1,535
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: ...
Seanny123's user avatar
  • 1,535
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: ...
John Ludos's user avatar
1 vote
1 answer
166 views

Vectorizing in Python [closed]

I have the following code: ...
FacundoGFlores's user avatar
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 ...
Daniele's user avatar
  • 91
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 ...
Max Rosett's user avatar
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 ...
andrew's user avatar
  • 215
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. ...
S.Later's user avatar
  • 31
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 ...
Seanny123's user avatar
  • 1,535
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? <...
Seanny123's user avatar
  • 1,535
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 ...
Dataman's user avatar
  • 227
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. ...
Dataman's user avatar
  • 227
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 ...
Prashanth's user avatar
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 ...
marcopolo's user avatar
  • 131