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

learn more… | top users | synonyms

3
votes
3answers
53 views

Creating and manipulating FITS files

I wrote a program that manipulated data from VLA observations and created FITS files to be used in creating spectral energy distributions of high redshift radio galaxies. I really tried to be as ...
2
votes
2answers
47 views

Efficiently index rows of numpy array by exclusion

I need a function that takes a numpy array and a row number as inputs and returns the array (or copy of the array) excluding the given row. I want to do this as efficiently as possible. ...
2
votes
1answer
46 views

Skip list in Python

I've made an attempt at writing a skip list in Python. I'm using NumPy to generate geometric random variables, but since that's a bit of a heavy dependency to drag around I could easily implement that ...
3
votes
1answer
31 views

Comparing pixels against RGB value in NumPy

Assume I created an image in NumPy: image = imread(...) And the image is RGB: ...
5
votes
2answers
84 views

Attempting to run multiple simulations of the Gillespie algorithm for a set of stochastic chemical reactions in less than 10 minutes

I have written Python code that generates a plot. In the code below, when I set maxtime = 0.1, the program takes ~50s and when I set ...
2
votes
0answers
15 views

Speed up structured NumPy array [migrated]

NumPy arrays are great for both performance and easy use (easier slicing, indexing than lists). I try to construct a data container out of a ...
1
vote
1answer
36 views

Write binary save file in Python

I'm fixed on the save file format. There are only three types of data: long (NumPy int32 array, independent of platform) ...
5
votes
2answers
109 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
0answers
17 views

Spatial parametric scaling in agent-based model

I’m running a simple agent-based disease spread model on a 2D lattice, where disease transmission in a population depends on each individual’s chance of avoiding infection at every time step, which ...
4
votes
2answers
102 views

Backtracing Sudoku solver

I have made a backtracking Sudoku solver in Python but it's working quite slow. Originally, It had been working on 4 by 4 grids, which worked fine. But now, trying to solve 9 by 9 grids takes a very ...
8
votes
2answers
55 views

Iterate list to map entries in Python

I have two files, namely: File1: CL1 AA XX YY ZZ SS \n CL2 3_b AA File2: AA string1 AA string2 3_b string3 My ...
9
votes
2answers
90 views

A 3-D vector class built on top of numpy.array

I wanted a convenient class to easy access the parameters inside. I am using a lot of math in my game; that's why a wanted to access them through x, ...
6
votes
1answer
90 views

Optimizing a python script with large arrays

I have a python script that I'd like to speed up. I'm hoping some of the gurus here can offer some advice. The script reads in some data from file: 2 arrays with lat/lon vals, 3 arrays with image ...
6
votes
1answer
176 views

Combining two clock tick vectors with NumPy

I have two long (7683200 length) 1D arrays corresponding to two clock cycles, that I wish to combine into single 1D array. The clock_ticks_fine cycles between ...
13
votes
3answers
289 views

Orbital Trajectory simulator

I have written a simple program to do trajectory simulation in the Earth-Moon system, it still has a long way to go I am working on making it more class oriented and am looking into implementing a ...
5
votes
1answer
64 views

A matplotlib scatter function inside a for loop

This function is working exactly as I want, only, it's taking too long. For speed ups, I've tried to do as much as I can before the main for loop by declaring ...
0
votes
1answer
90 views

Benchmark using floating point math

I wrote some code in Python, to benchmark mathematical operations. It does not do anything in particular besides just calculating a lot of floating point numbers. To clarify: I need 128-bits ...
6
votes
3answers
86 views

Python differential analysis of heat loss across a pipe

I made a differential equation solver to forecast heat loss through a pipe with heat loss coefficient contours. It does what I want it to do but I had to use global variables to change the outputs of ...
2
votes
1answer
59 views

Cross validation of gradient boosting machines

I am fairly new to Python. I implemented a short cross-validation tool for gradient boosting methods. ...
3
votes
1answer
105 views

“back substitution” method for solving linear system

I'm using numpy to write the "back substitution" method for solving linear system where "A" is a nonsingular upper triangular matrix. ...
1
vote
1answer
60 views

Latent Dirichlet Allocation in Python

I've recently finished writing a "simple-as-possible" LDA code in Python. The theory from which I've developed my code can be found in the book Computer Vision by Simon Prince, free (courtesy of ...
4
votes
1answer
85 views

Applying a formula to 2D numpy arrays row-wise

The user has two 2D input arrays A and B, and a given matrix S. He wants to apply a ...
2
votes
1answer
35 views

Extracting an arbitrary element from each row of a np.array

I have a large numpy array of shape (n,m). I need to extract one element from each row, and I have another array of shape (n,) that gives the column index of the element I need. The following code ...
3
votes
0answers
775 views

ID3 Decision Tree in python

I've been working my way through Pedro Domingos' machine learning course videos (although the course is not currently active). His first homework assignment starts with coding up a decision tree ...
1
vote
3answers
50 views

Convert scalar arguments to arrays, and check that lengths are equal

I've got a Python function that takes two arguments, lat and lon. These arguments can be either scalar values (...
6
votes
1answer
101 views

Fastest possible Cython for Black-Scholes algorithm

I started with a pure python implementation, and have been trying to get the performance as close to native C as possible using numpy, numexpr, and cython. Here is the the numpy version that I ...
5
votes
1answer
52 views

Slicing time spans into calendar months

I have apparently correct code that still runs for weeks on my data (tens of millions of rows). I show the entire code for reference (and maybe other gains to be made), but the key operation is in the ...
2
votes
1answer
53 views

Create symmetrical matrix from list of values

I need to make a matrix (in the form of a numpy array) by taking a list of parameters of length N and returning an array of dimensions N+1 x N+1 where the off-diagonals are symmetric and each triangle ...
4
votes
3answers
209 views

Kadane's Algorithm for 2D array with known boundaries

I asked this question first on StackOverflow but I didn't get an answer and was advised to try here too. So here we go. I have implemented Kadane's algorithm for a 2D array in Python 2 with known ...
5
votes
5answers
58 views

Create matrices of a certain format

I need to create matrices that follow a specific format: the matrix is a square NxN matrix and the off-diagonals all have the same value (param) and the diagonals ...
11
votes
1answer
320 views

Balanced Random Assignment in Python

It has been a very long time since I've used Python. What I'm looking for: I would like to create a 6-by-6 random matrix where each component is either 1 or 2, so that there are 18 ones and 18 twos. ...
12
votes
1answer
117 views

Racetrack plotter

My Racetrack is just that. A Racetrack. You can't race it (yet) because I had trouble with collision detection, but I wanted to share it anyway. It creates a base polygon by using ...
2
votes
1answer
42 views

Numba mergesort

I have written a mergesort in Python/Numba: ...
3
votes
0answers
50 views

2D disease problem modeling [closed]

I'm modeling a disease problem where each individual in a 2D landscape has a transmissibility described by a (radial basis) kernel function. My goal is to convolve the kernel with the population ...
3
votes
2answers
93 views

Duplicate the previous input if zero or not a number

I have the following code which duplicates the previous input if any entry is less than zero or NaN, except the first row of a matrix. Is there any other efficient way to do this without using ...
6
votes
3answers
168 views

Numerical Python code to generate artificial data from a time series process

I'm writing code to generate artificial data from a bivariate time series process, i.e. a vector autoregression. This is my first foray into numerical Python, and it seemed like a good place to start. ...
8
votes
1answer
160 views

A big “Game of Life”

Our quest: Create a big simulation for Conway's Game of Life, and record the entire simulation history. Current Approach: Cython is used for an iterate method. The ...
2
votes
1answer
38 views

Similar manipulations on several numpy arrays

I have n numpy arrays which all contain time series data for t periods. It is not an option to instead have one ...
10
votes
2answers
158 views

Numerics for a game theory calculation using expected utility

I am trying to replicate Bruce B. de Mesquita's (BDM) results on political game theory for prediction. Based on where actors stand on issues, their capabilities, salience, BDM's method attempts to ...
3
votes
1answer
215 views

Imputing values with non-negative matrix factorization

X is a DataFrame w/ about 90% missing values and around 10% actual values. My goal is to use nmf in a successive imputation loop to predict the actual values I have ...
4
votes
1answer
254 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 ...
5
votes
1answer
146 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
489 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
73 views

Vectorizing in Python

I have the following code: ...
3
votes
1answer
95 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 ...
4
votes
3answers
231 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
70 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
218 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
67 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
1k 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 ...