Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
0 answers
142 views

Find the available squares for rooks in empty board using boolean arrays

I will describe two techniques, then the question will be how I can make an algorithm that is more efficient, if possible. I want to find an efficient way to determine the squares where the pieces on ...
3sm1r's user avatar
  • 143
0 votes
1 answer
528 views

Image color-moment extractor [closed]

I was just wondering if there is a way to speed up the performances of this for loops in Python. I'm trying to process an image to get the color-moments without using libraries. It takes about 12sec ...
Enrico Mosca's user avatar
2 votes
0 answers
122 views

Extract cell values from multiband rasters

I have the following function and code snippet to extract cell values for multiple years, format it, and save to a list. Each raster has 365 bands — one for each day. A separate operation is performed ...
Ibe's user avatar
  • 121
5 votes
1 answer
1k views

Improving the speed of creation for three Perlin Noise Maps in Python?

I am interested in learning how I can improve the speed of the code in this pygame file. I iterate over 6400 * 1800 * 3 or 34,560,000 elements of various numpy arrays here to apply noise values to ...
LuminousNutria's user avatar
7 votes
1 answer
1k views

Plotting terrain pixels with PyGame based on random NumPy array

I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list that I call from the singleton ...
LuminousNutria's user avatar
2 votes
3 answers
437 views

Code to find the sum of the product of all size-n combinations of an array

The title is a bit of a mouthful, so here's a quick example: You've got an array, maybe just the digits 1-3, and you want to get the sum of product of all size-2 combinations of the array. Those ...
rp0's user avatar
  • 23
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
3 votes
2 answers
4k views

Calculate True Positive, False Positive, True Negative and False negative and colourize output

Objective : Calculate True Positive, False Positive, True Negative and False negative and colourize the image accordignly, based on ground-truth and prediction from my classifier model. Problem : ...
user avatar
5 votes
1 answer
211 views

Using NumPy to scale data in 2 out of 3 columns

The below code takes a csv containing age, weight, height and prints the betas determined through linear regression to an output csv. It runs for 10 iterations using a different alpha for each, and ...
user7875185's user avatar
5 votes
1 answer
5k views

Applying Laplacian smoothing to vertices in a mesh

I'm totally new in Python and I wrote some code. It is a simple algorithm to smooth objects. I need to find adjacent vertices in mesh and sum their coordinates and after that divide by a number of ...
Pagorek's user avatar
  • 51
3 votes
0 answers
1k views

Implementing the stochastic gradient descent algorithm of the softmax regression with only NumPy [closed]

I am implementing the stochastic gradient descent algorithm. I think there is plenty of room for improvement. ...
Lerner Zhang's user avatar
5 votes
2 answers
1k views

A command-line utility to solve a system of linear equations

I was re-checking my answers for a Math paper on my laptop. I needed to verify my solution for a system of linear equations. Unfortunately, I found no quick way to do that. That's why I wrote a (...
Hungry Blue Dev's user avatar
5 votes
2 answers
849 views

Python Cartesian Product in a constrained dictonary

I want to calculate the Cartesian product of n copies of a small list, marker=[0,1,2]. I want to use these Cartesian product ...
Zhubarb's user avatar
  • 245
4 votes
1 answer
335 views

Surface Density Profile

I am trying to compute the surface density profile, given the spherical density profile in 3D for different parameters in order to interpolate and have it as a function of them to use later on for ...
Sketos's user avatar
  • 53
2 votes
1 answer
181 views

Slicing a big NumPy array

I have a function that takes a four-dimensional NumPy array M and, for each value i of its second index, takes all of M without the i-th "column", evaluates the product over all other columns, and ...
blue's user avatar
  • 123
3 votes
3 answers
600 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 ...
Joseph Farah's user avatar
9 votes
1 answer
4k 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 ...
os1's user avatar
  • 201
2 votes
1 answer
781 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 ...
Iwko's user avatar
  • 43
8 votes
3 answers
2k 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 ...
kilojoules's user avatar
6 votes
4 answers
2k 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 ...
ChrisG's user avatar
  • 163
11 votes
1 answer
2k 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. ...
Clarinetist's user avatar
14 votes
1 answer
1k 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 ...
Mast's user avatar
  • 13.5k
3 votes
1 answer
394 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 ...
NaN's user avatar
  • 218
3 votes
1 answer
1k 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 ...
jgreener's user avatar
  • 153
1 vote
2 answers
273 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 ...
john mangual's user avatar
2 votes
1 answer
690 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 ...
adrienlucca.net's user avatar
10 votes
1 answer
14k views

K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
Frames Catherine White's user avatar
4 votes
1 answer
200 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 ...
Bas Jansen's user avatar
3 votes
2 answers
726 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 ...
Scott's user avatar
  • 131
3 votes
1 answer
7k views

Fast loop to create an array of values [closed]

I have a code that creates a 3D array of values from a minimum to a maximum in X and Z with constant Y. Right now I make it in normal Python, and then I transform it in a ...
adrienlucca.net's user avatar
8 votes
2 answers
30k views

K-means clustering in Python

The following code uses scikit-learn to carry out K-means clustering where \$K = 4\$, on an example related to wine marketing from the book DataSmart. That book uses excel but I wanted to learn Python ...
Martin Leslie's user avatar
14 votes
1 answer
10k views

Faster computation of barycentric coordinates for many points

I'm just starting to understand the Python syntax and I created a module that does what I wanted, but really slow. Here are the stats of cProfile, top 10 ordered by ...
adrienlucca.net's user avatar