Questions tagged [numpy]
NumPy is the fundamental package for scientific computing with the programming language Python.
765 questions
52
votes
3
answers
172k
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 ...
25
votes
2
answers
28k
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 ...
25
votes
1
answer
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 ...
24
votes
2
answers
58k
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 ...
24
votes
3
answers
5k
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:
...
24
votes
2
answers
96k
views
Scale Numpy array to certain range
As I've described in a StackOverflow question, I'm trying to fit a NumPy array into a certain range.
Here is the solution I currently use:
...
21
votes
1
answer
762
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). ...
20
votes
4
answers
17k
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:
...
19
votes
1
answer
6k
views
Pretty printing of the numpy ndarrays
Following this idea for pretty printing of numpy ndarrays, I have developed a very primitive prototype:
...
19
votes
2
answers
11k
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 ...
18
votes
2
answers
97k
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 ...
18
votes
1
answer
7k
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 ...
17
votes
1
answer
616
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 ...
17
votes
1
answer
583
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 ...
16
votes
1
answer
451
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 ...