NumPy is the fundamental package for scientific computing with the programming language Python.

learn more… | top users | synonyms

2
votes
2answers
18 views

Computation of inter-grid distance array for 2D lattice

I have a 2D lattice with U × U number of grids. My goal is to create an array – of shape U^2 × U^2 – where each entry denotes the least-distance between each grid and any other grid. Currently, for ...
2
votes
1answer
48 views

Lattice lotka-volterra

Can anyone comment on the efficiency of my code? I am new with Python using NumPy/SciPy and I am trying to program a lattice biological model where a certain (one and only one) species (represented by ...
1
vote
2answers
19 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 ...
3
votes
1answer
183 views

Labeling alternating max/mins based on a user defined delta

Given a set of values (points on a graph) find all the max/min points such that there is no max is followed by a max (i.e. the max and min points alternate) there is some minimum amount of change ...
3
votes
1answer
73 views

Iterative equation solver in Python

In order to solve a equation where the left hand side appears under an integral on the right hand side: $$ B(p^2) = C\int_0^{p^2}f_1\left(B(q^2),q^2\right)\mathrm{d}q^2 + C\int_{p^2}^{\Lambda^2} ...
3
votes
1answer
43 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 ...
4
votes
1answer
87 views

Triangle rasterization using a scanline algorithm for numpy array indexing

I need to access those elements of a large numpy array that lie in a small triangular area. The brute force solutions of using ...
8
votes
2answers
133 views

Predator Prey Simulation

Below is a simple random walk predator prey simulation that is optimized to the best of my abilities. I would love to hear about any improvements that can made. ...
1
vote
1answer
23 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. ...
4
votes
2answers
79 views

Averaging lists of values with duplicate keys

I have gene expression data that I represent as a list of genes and a list of lists of values. I average the expression data for any genes with the same name. For example: ...
5
votes
2answers
74 views

Opening and writing multiple files using minimum script

Can it possible to make this script short, so that multiple data and multiple output file can be managed efficiently? ...
14
votes
1answer
145 views

Remapping and interpolating 255x1024 array

I have a function that accepts a \$255\times1024\$ array and remaps it to another array in order to account for some hardware related distortion (lines that should be straight are curved by the lens). ...
4
votes
0answers
42 views

Resource-constrained project scheduling

I'm trying to implement an algorithm for a resource-constrained project scheduling problem. I have several resources, resource constraints and all of this is in ...
2
votes
1answer
56 views

Optimize Python script for generating Point Cloud

I'm trying to produce a 3D point cloud from a depth image and some camera intrinsics. The image is 640x480, and is a NumPy array of bytes. The output is a (rows * columns) x 3 array of points. I've ...
2
votes
1answer
33 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 ...
1
vote
1answer
43 views

Moving window with complete boundary in Python

I asked this question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example: ...
1
vote
2answers
101 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? ...
3
votes
1answer
71 views

Iterate over coordinates and correct constraint violations

I am creating an algorithm to take a series of labelled points placed randomly and move them until they fulfil a set of constraints. The constraints have been pre-computed and are each a lower and ...
5
votes
2answers
349 views

Calculating the volume of a tetrahedron

Here's my function for calculating the volume of a tetrahedron. I've tried to comment well and perform a few checks on the types of the objects passed to it. Can ...
3
votes
1answer
77 views

Confidence score calculation

I was looking for a way to calculate a score 'x' for each pair of elements in two separate arrays. The goal of the code is to return an output array containing the score for each entry in the input ...
3
votes
1answer
78 views

Look up parameters based on a numpy array of input values

Aim: Write a function that looks up empirical parameters A, B and C for a solar radiation ...
4
votes
1answer
168 views

Harmonic analysis of time series applied to arrays

I've developed some code in Python to apply a harmonic analysis of timeseries (for satellite imagery data). It's based on this, but then I would like to optimize the performance. So instead of a ...
3
votes
2answers
60 views

Scoring system of a pool of dice

I want to do some Monte Carlo simulations on a system based on a pool of dice. For each trial, a number of dies are rolled, and the winner is the highest value, getting as many points as dice are over ...
4
votes
1answer
148 views

Intersection between arrays

I'm a Python beginner (more used to code in R) and I'd like to optimize a function. 2 arrays ares filled by integers from 0 to 100. A number can't appear twice in a row and they're stored in an ...
2
votes
1answer
31 views

Printer Color Templates

I'm new to Python and I just wrote my first program with OOP. The program works just fine and gives me what I want. Is the code clear? Can you review the style or anything else? ...
1
vote
1answer
50 views

Improving excution time for list and sampling in Python

Here is my code for generating edge list based on Price model algorithm. I think there have two points to reduce execution time: use proper data type use faster random sampling Originally, I used ...
0
votes
1answer
94 views

Where's the bottleneck in this tvtropes.org scraper?

...
4
votes
1answer
118 views

Generate sample coordinates inside a Polygon

I have a Polygon named as poly. I attempted to randomly select 5 coordinate points that lies inside the polygon. ...
1
vote
0answers
71 views

Fastest computation of N likelihoods on normal distributions

In the context of a Gibbs sampler, I profiled my code and my major bottleneck is the following: I need to compute the likelihood of N points assuming they have been drawn from N normal distributions ...
1
vote
2answers
131 views

Sieve of Erathosthenes speedup

While reading HackerNews, I learned about a data set of the first 50 million primes. This would be a lot, but his website has disclaimer: n this directory I have the first fifty million primes in ...
3
votes
1answer
85 views

Calculating the distance squared between all vertex-pairs of a number of 2D polygons

I have implemented my code using Cython. It is the current bottleneck in my computations. There are two non-numpy functions involved: calculate_2D_dist_squared ...
2
votes
1answer
140 views

Speed up a function using NumPy

I have a function written in Python 2.7 that I call several times in a program. This function is rather slow, and I'd like to rewrite it in NumPy. However, I don't know how to do it. I basically have ...
3
votes
0answers
75 views

Find binary sequence in NumPy binary array

As part of creating a software defined receiver and decoder, I want to find sync pulses in weather satellite data. The data is first digitized to a 0-1 array. The code below is working. The ...
2
votes
2answers
163 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 ...
3
votes
1answer
169 views

Python implementation of multidimensional power spectral density with Welch method

I have done my best to write Welch method implementation for python for multidimensional time series and still in the case of one dimensional time series I am getting inconsistent response compared to ...
4
votes
1answer
88 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. ...
5
votes
1answer
72 views

Optimizing a loop for 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 ...
1
vote
1answer
51 views

List of lists of arrays, zipping, modifying in place

I came back to some old code today and freaked out. I was like "How does this even work, and if it works it can't do what I intended." I ran a few quick tests and confirmed it did actually do what ...
3
votes
1answer
67 views

Averaging a list of intersecting rectangles

I have a list of rectangles as tuples (x, y, w, h). I need to find which ones intersect and if they do, average all the intersecting rectangles into a new rectangle. I also track the resultant ...
5
votes
2answers
121 views

Monte Carlo estimation of the Hypergeometric Function

I am trying to implement the algorithm described in the paper Statistical Test for the Comparison of Samples from Mutational Spectra (Adams & Skopek, 1986) DOI: 10.1016/0022-2836(87)90669-3: $$p ...
3
votes
1answer
331 views

K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
6
votes
1answer
513 views

Groupby in NumPy

To avoid the XY problem, here is an example of what I need. Given the sorted integer input array [1 1 1 2 2 3], I would like to produce the following slices, ...
4
votes
1answer
54 views

Stable partition in Numpy

In essence, I need to do a stable partition: All elements of the 1D np.array a that are present in ...
3
votes
1answer
113 views

Where is the bottleneck in my Cython code?

The profile tells me it took ~15s to run, but without telling me more. ...
2
votes
1answer
116 views

Neighbours from point connections

I am working with a mesh of triangles (in 3D, although I doubt it makes a difference). The mesh is given as list of lists, each list containing the indices of the three vertices of a triangle in said ...
3
votes
0answers
209 views

Parallelizing some model fitting code using multiprocessing

I'm trying to refactor some code for fitting parametric models that are defined symbolically using Theano. My goal is for all models to expose a common interface so that, as far as possible, they can ...
2
votes
1answer
94 views

How can I make this implementation of Euler's method more efficient?

I have an implementation of an Euler method for solving N-many 1st order coupled differential equations, but I feel that I did not write it as efficiently as I could, due to lack of programming ...
1
vote
0answers
50 views

Function that transforms input file based on a numpy poly1d function

I have written a function that gets a function as input (acquired from numpy.poly1d). The function has access to the GUI variables ...
3
votes
2answers
103 views

Reduction function in Rainbow tables implementation

I'm working on an implementation of Rainbow tables as part of a project. I understand the main principles behind it had have a working solution. Unfortunately the reduction function portion of my ...
8
votes
1answer
140 views

Interpolate then maximize

I need to optimize $$ \max_{a',\ m'} f(a, m, e, m', a') $$ I have approximated \$f\$ with a grid \$F\$ — it has shape \$(nA, nM, nE, nM, nA)\$. Now, I want to interpolate over the last two ...