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

learn more… | top users | synonyms

4
votes
1answer
79 views

Order a list of tuples or a NumPy array in a specific format

I have a list of tuples or a NumPy array (it can be either of them as the variable comes as a list and will end up being a NumPy array) and I want to order them in a specific way (that I am not able ...
4
votes
1answer
124 views

Comparing FFTs to deduplicate IVR recordings

I've got a Python script that traverses two file trees, checking all .wav files for duplication. I'm still an undergrad, and have never worked with audio before. I'm not entirely sure this is going ...
2
votes
2answers
39 views

Converting a 1D Array of Strings to a 2D Array in Python

I was solving this question on a site that gives you a 1d array called grid ...
1
vote
1answer
49 views

Vectorizing in Python

I have the following code: ...
3
votes
0answers
26 views

Reimplementing numpy.genfromtxt in Fortran for Python

I've found that the function genfromtxt from numpy in Python is very slow. Therefore I decided to wrap a subroutine with f2py to read my data. The data is a ...
3
votes
1answer
67 views

Rating tennis players in a database, taking days to run

I have this project in data analysis for creating a ranking of tennis players. Currently, it takes more than 6 days to run on my computer. Can you review the code and see where's the problem? ...
7
votes
1answer
61 views

Weighted phase Laplacian formula

We have the following equation (weighted phase Laplacian): \$c_{i,j} = U(i,j)\Delta^{^x}_{i,j} - U(i-l, j)\Delta^{x}_{i-1,j} + V(i,j)\Delta^{y}_{i,j} - V(i,j-1)\Delta^{y}_{i,j-1}\$ Where \$U(i,j) = ...
2
votes
1answer
51 views

Plotting non continuous functions and a real scatter example with Bokeh

I've written a python 3 code using Bokeh. With this code you can learn howto to plot math functions and a scatter plot with regression linear functions in a webpage. The target is how to plot ...
5
votes
1answer
51 views

Creating a flood from a seed point in an array

I have created a python script that takes a 2D NumPy array of elevation values and given a seed value and an elevation it will grow a flood from that seed point. It does this by checking all adjacent ...
11
votes
1answer
179 views

Sending a C++ array to Python/NumPy and back

I am going to send a C++ array to a Python function as NumPy array and get back another NumPy array. After consulting with NumPy documentation and some other threads and tweaking the code, the code is ...
1
vote
0answers
33 views

Calculating doubling times from data points

In the code below, noisy data points with unique errors are created. From this, an exponential function is fitted to the data points, and then doubling times (10 unit windows) are calculated. I'm ...
5
votes
1answer
74 views

Python factory method with easy registry

My aim is to define a set of classes, each providing methods for comparing a particular type of file. My idea is to use some kind of factory method to instantiate the class based upon a string, which ...
2
votes
2answers
79 views

Computation of population patterns in simple agent-based model

I've modeled the population changes for a group of agents that inhabit a 2D lattice (with wrapped boundaries) made up of M x M number of grids. At each time step: ...
8
votes
2answers
171 views

Approximate (250 over 100) permutation best fitting certain criteria

Given a list of 250 words of 4 letters each, what is the fastest way, in Python, to find a subsample of 100 words (drawn without replacement) so that the distribution of letters across the whole ...
4
votes
2answers
115 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 ...
3
votes
1answer
88 views

NumPy array filter optimisation

I've got a filter that I'd like to work out how to optimise. The most basic implementation, using loops is like the following: ...
6
votes
1answer
125 views

Statistics about gaps in DNA sequences

Noobie to Numba here, I'm trying to get faster code from existing function but the result is not faster. 10 times faster would be heaven, but I know nothing about optimization. This is code about ...
3
votes
1answer
109 views

Instantiating a kind of NumPy array

I am creating a class object which must inherit from numpy ndarrays. I perform an isinstance check and an ...
3
votes
3answers
93 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
108 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
42 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
187 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 ...
5
votes
1answer
125 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
63 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
153 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
283 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
36 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
94 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
111 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
168 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
66 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 ...
5
votes
1answer
151 views

Generating a 3D 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
39 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
1answer
78 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
267 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
90 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
448 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
98 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
85 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
247 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
69 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
279 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
32 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
57 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
103 views

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

...
4
votes
1answer
141 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
99 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
136 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
106 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
194 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 ...