# Questions tagged [numpy]

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

518 questions
Filter by
Sorted by
Tagged with
68k views

### Finding the closest point to a list of points

I'm trying to find the closest point (Euclidean distance) from a user-inputted point to a list of 50,000 points that I have. Note that the list of points changes all the time. and the closest distance ...
1k views

### Backpropagation in simple Neural Network

I've been working on a simple neural network implemented in python. Currently, it seems to be learning, but unfortunately it doesn't seem to be learning effectively. The graph below shows the output ...
3k views

### Remove points in a straight line

I wrote this code to remove points that create a straight line when plotted. For instance, this has many points in a straight line: ...
15k 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 ...
570 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). ...
6k views

### Finding a zero crossing in a matrix

I am trying create an algorithm for finding the zero crossing (check that the signs of all the entries around the entry of interest are not the same) in a two dimensional matrix, as part of ...
302 views

### Solve the phase state between two haplotype blocks using markov transition probabilities

I have spent about more than a year in python, but I come from biology background. I should say I have got some understanding of for-loop and nested-for-loop to workout the solution to the problem I ...
25k views

### Crop black border of image using NumPy

Objective: Crop the image so only the number stays in the image Problem: Slow Performance I have code that crops an image. The image pixels are 0 or 255. There are no values between. The ...
79k views

### Fastest way to iterate over Numpy array

I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to ...
371 views

### Warhammer: How many of my attacks will succeed?

Me and a couple of mates sometimes play a game called Warhammer. When playing the game you have options of what each model attacks. This can lead to situations where you know if you shoot with 100% of ...
390 views

### MNIST Deep Neural Network in TensorFlow

I have been working on this code for a while and it gave me a lot of headaches before I got it to work. It basically tries to use the MNIST dataset to classify handwritten digits. I am not using the ...
9k views

### Processing an image to extract green-screen mask

I am using OpenCV to process an image, and in my code, I have to check / edit each pixel separately: ...
4k 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 ...
1k views

### Plot timings for a range of inputs

When writing Code Review answers, it becomes often necessary to measure how long the modified code takes vs how long the OP's code takes. I needed a nice way to visualize this as a function of the ...
469 views

### Plotting different parameterized polynoms

For a university assignment I had to plot different polynomial functions depending on one single parameter. That parameter gave the number of supporting points to interpolate a given function in the ...
8k views

### Possible optimizations for calculating squared euclidean distance

I need to do a few hundred million euclidean distance calculations every day in a Python project. Here is what I started out with: ...
442 views

### Generating Julia set

So, I just wanted to post something on Rosetta Code, and I found this task of generating and plotting a Julia set: http://www.rosettacode.org/wiki/Julia_set. There was already one solution but it was ...
484 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 ...
796 views

### Plotting polynomials roots

NOTE: See follow up to this question here I created a simple python script to plot quadratic, cubic and quartic polynomials with integer coefficients between -4 and 4. It uses numpy to find the roots ...
268 views

### Efficiently selecting spatially distributed weighted points

Background: Motivation behind writing the following code is originated in the area of computer vision. More specifically – image rectification. In order to obtain rectified images, one has to find a ...
5k 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 ...
715 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 ...
712 views

### Temperature Interpolation

I want to interpolate temperature in correlation with height. I have temperature data from stations with coordinates and height in this format: ...
1k views

### Pretty printing of the numpy ndarrays

Following this idea for pretty printing of numpy ndarrays, I have developed a very primitive prototype: ...
1k views

1k 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 ...
24k views

### Efficient numpy cosine distance calculation

I want to calculate the nearest cosine neighbors of a vector using the rows of a matrix, and have been testing the performance of a few Python functions for doing this. ...
13k views

### K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
846 views

### KenKen solver - Python

Here is my code for the KenKen puzzle: The user must fill in each embolded regions with numbers in the range 1-n where n is the board dimensions (e.g: 4*4, n=4) ...