# Questions tagged [numpy]

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

35 questions
Filter by
Sorted by
Tagged with
1answer
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 ...
1answer
13k views

### K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
1answer
6k 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 ...
1answer
494 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 ...
1answer
2k views

### Game of Life with NumPy

I started this exercise with NumPy with a goal to find neighbors and return the new matrix. I want to get your feedback. Here's an example from this website. It looks like it's $O(N^2)$, and I'm ...
2answers
4k views

### Python / Numpy running 15x slower than MATLAB - am I using Numpy effeciently?

Here is some code I wrote in Python / Numpy that I pretty much directly translated from MATLAB code. When I run the code in MATLAB on my machine, it takes roughly 17 seconds. When I run the code in ...
1answer
379 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 ...
1answer
807 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 ...
2answers
10k 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 ...
1answer
2k views

### Remove pixel patch in image which is stored as array

I have an array I which stores N images of size P (number of pixels). Every image is of size ...
1answer
341 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 ...
1answer
578 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 ...
2answers
6k views

### Python, numpy, optimize module to handle big file

With the help of some people here and there, I wrote the module below which works very well if the file targets.csv is not too big. As soon as this file exceeds ...
1answer
914 views

### Hints to make Sudoku solver more Pythonic

As you will see, I am not very familiar with Python and NumPy but want to learn it. The following code is a very basic Sudoku solver which works fine for simple examples. Although it runs, I still ...
2answers
3k views

### Simulation of 2D elastic balls

Following this SO post and this Wikipedia article, I wrote a Python script to simulate physics of 2D elastic balls. I define the physical behaviour of each ball in the ...
1answer
1k views

### Python program that draws the Mandelbrot set fractal

I wrote a Python program that draws the Mandelbrot set fractal. However, the program is very slow. I would appreciate any feedback on the program, but I would especially appreciate feedback on how to ...
1answer
153 views

### Population dynamic simulation on biological information maintenance

Background Using this simulation I investigate a system in which enzymes proliferate in cells. During the replications of enzymes, parasites can come to be due to mutation. They can drive the system ...
1answer
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. ...
0answers
168 views

### Population dynamic simulation on biological information maintenance 2

This question is the follow-up to this previous question. Background Using this simulation I investigate a system in which enzymes proliferate in cells. During the replications of enzymes, ...
3answers
561 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 ...
1answer
11k views

### “Histogram of Oriented Gradients” (HOG) feature detector for computer vision

Here is a function that I've only slightly modified from its original context, found here. Before mentioning anything else, it should be noted that I'm desperately trying to optimize this code for ...
2answers
146 views

### Temporal kernel filtering on video frames coming in a loop

I have a video which I read in a loop frame by frame. For every frame, I want to do temporal kernel filtering, the coefficients of which come from the input variable model (a dictionary). The temporal ...
3answers
308 views

### Estimating the number of tanks based on a sample of serial numbers 2.0

There was some confusion with the code I had posted in my previous version of this question and there was some good advice from @Oscar Smith. The explanation is the same; please give improvements for ...
2answers
4k views

### Calculating if a point is within a polygon, or outside of it

Here is the function (along with its support functions): ...
0answers
202 views

### Finding where column slices of elements in multi-dimensional array are equal

Skippable Intro: I have a dataset that corresponds to an observed time-series. The dataset is organized into a dictionary - which contains an array of years, an array of months, an array of days, an ...
1answer
98 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) = ...
1answer
595 views

### Python! (Snake)

This is now an Iterative Review. Next Iteration Nowhere near a full game yet. Just a basic overview and initialisation of a Snake() class. Thoughts? ...
1answer
1k views

### Koch snowflake in Python with numpy and pygame

I've drawn a Koch snowflake with Python 3. I'm new to the Python world and would appreciate all feedback on how to make the code more Pythonic as I'm not used to these idioms, styles and modules. All ...
1answer
1k views

### Reading a binary file containing periodic samples

I have the following code for reading HTK feature files. The code below is working completely correct (verified it with unit tests and the output of the original HTK toolkit). ...
2answers
595 views

### Simple one-hot encoder

Because neither sklearn nor Pandas provide a straightforward and complete one-hot encoder, I decided to write one myself. Both Pandas and sklearn do have an encoder with no option to decode, and the <...
1answer
67 views

### Getting angle between all points in array

I have got some code that calculates the angle between all of the points in an array. It works, but it is quite slow. This is because it has complexity O(n^2). It has to loop through the array and ...
1answer
146 views

### Simple utility/convenience module - am I doing it right?

I have a large library (four packages) of data processing code that I have written over the last 12 months. I am quite new to python and would like to see if I am doing things correctly. This utility/...
2answers
1k views

### Rolling loop with an array of data points

I have a NumPy array of about 2500 data points. This function is called on a rolling basis where 363 data points is passed at a time. ...
0answers
60 views

### Improving code for image manipulation

I'm fairly new to coding and am developing a set of functions to allow mammologists to progrmatically collect data from photos of specimens. The special issue with mammals is that their coats are ...
1answer
2k views

### Data cleaning - am I using classes correctly here?

I have a data processing application that does some data cleaning as the first step. This is the module I import for that purpose. The only 'public' part of the api is the 'clean' function which ...