Questions tagged [numpy]

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

Filter by
Sorted by
Tagged with
3
votes
1answer
50 views

Hurst Exponent calculator

I am aiming to compute the Hurst Exponent of a 1-D signal time series in Python. For now, I have one existing function hurst(sig) which returns the Hurst exponent ...
3
votes
1answer
22 views

Converting string of hex values to numpy array of specific shape

I am working on a project that needs to take a .bdf font file and turn it into a Numpy array. I am using the code below to turn the bitmap for the font into a numpy array. It currently works, I just ...
2
votes
1answer
33 views

Trapezoidal rule for set of data

Here is the question from the book of Mark Newman-Computational Physics Exc 5.1 a) Read in the data and, using the trapezoidal rule, calculate from them the approximate distance traveled by the ...
3
votes
2answers
88 views

Calculate mean and standard error of a generator in Python

The goal of the following code is to calculate the mean and the standard error of vectors of randomly-generated numbers. I am looking for feedback both on the correctness of the calculation, and on ...
1
vote
0answers
22 views

Parsing and plotting with numpy (or pandas)

I am trying to improve the following code to make it more broadly applicable and quick to use. ...
2
votes
2answers
108 views

Performance issues with double for loops, EM-algorithm

The alpha that I create is not created in a crazily efficient way I know, but the main bottleneck in this code is in what I call the "Maximization step" (see comments in code). There are double for-...
4
votes
1answer
70 views

Optimising iteration and substitution over large dataset

I have the following code: ...
0
votes
1answer
50 views

Nested list performance tuning

I need to make a function like these two, but at least an order of magnitude faster in python. Any tips or tricks? These functions inputs are nested lists, like: ...
7
votes
1answer
54 views

Generating Latin hypercube samples with numpy

I wrote some code to generate Latin hypercube samples for interpolation over high-dimensional parameter spaces. Latin hypercubes are essentially collections of points on a hypercube that are placed on ...
9
votes
3answers
850 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) ...
4
votes
1answer
85 views

Agent based model in Python

My model is based on the Ultimatum Game. I won't go into the intuition behind it but generally speaking it functions as follows: The game consists of a n × n lattice on which an agent is placed at ...
3
votes
0answers
32 views

Implementing a tic tac toe board in python

This is my attempt at making a class to represent a game board for tic tac toe. I normally hate while loops but I used one because I cant seem to make the ...
1
vote
0answers
28 views

Sortings stocks into quantiles based on their signal

This function sorts stocks into quantiles. To do so I used this function that accepts sig_df (dataframe with the timeseries of stocks signal) and number of ...
2
votes
1answer
41 views

Grid class for games using python

I made this class to eventually create a tic tac toe game. I used numpy which is a first for me. Here it is: ...
2
votes
1answer
35 views

Efficient resampling of time series

I'm trying to create an efficient function for re-sampling time-series data. Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.) Resample ...
5
votes
1answer
58 views

Pad a ragged multidimensional array to rectangular shape

For some machine learning purpose, I need to work with sequences with different lengths. To be able to process efficiently those sequences, I need to process them in batches of size ...
6
votes
2answers
88 views

Positive cumulative sum of difference

I have a water reservoir with input and output rates. I want to determine when the input is exceeding the output by a certain constant. To accomplish this, I need to cumulatively sum all cases where ...
2
votes
1answer
49 views

Select optimal piecewise regression fit

I'm making a program which fits a piecewise linear regression with up to 4-5 breakpoints in the data, and then deciding how many breakpoints is best to prevent over and underfitting. However, my code ...
5
votes
3answers
123 views

Python solution for the N-Queens challenge

Here is my coded solution for the N-queens challenge The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. The program outputs all ...
3
votes
0answers
54 views

Optimising Probabilistic Weighted Moving Average (PEWMA) df.iterrows loop in Pandas

I'm implementing the Probabilistic Exponentially Weighted Mean for real time prediction of sensor data in pandas but have issues with optimising the pandas notebook for quick iterations. Is there a ...
6
votes
1answer
90 views

Choosing evenly distributed points from a million points on a sphere

I have \$10^5\$ to \$10^6\$ points on a sphere, and want to choose some points from them which are as close as uniformly distributed as possible. For that reason, I do the following: at each step I ...
4
votes
1answer
46 views

Gravity simulation using Numpy and Pygame

This is a simple gravity simulator coded in Python 3.7 using Numpy and Pygame. I was wondering if it can be optimized further. Initially I had coded it using pure Python lists, using nested loops to ...
6
votes
0answers
54 views

Numerical integration in cython

I have a set of nested functions that I need to call multiple times. I know scipy.quad is pretty fast, but I will need to call the integrator recursively and want ...
6
votes
0answers
51 views

Find indices using for loop

I should estimate the effect of B fields on particle deflection using \$F=V \times B \times Force\$. I have a 2D mesh with \$n_x\$ and \$n_y\$ which show the number of points in each direction. \$B\$ ...
2
votes
0answers
47 views

Python list operation - merge adjacent cubes into minimum number of shapes

I am hoping to find a way to make the process a lot faster. The lists are made of rows of 6 numbers, i.e. [[float] * 6, ...]. The intent is to pass a list of cube ...
3
votes
2answers
78 views

3D metrics for segmentation evaluation

I am new to programming and I am trying to develop a machine learning approach for image segmentation (https://en.wikipedia.org/wiki/Image_segmentation) and here I want to evaluate the predicted (...
2
votes
0answers
44 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 ...
8
votes
0answers
160 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, ...
4
votes
1answer
54 views

U-Net: A TensorFlow model

What I want to know I am writing a ML model called U-Net with Python (and TensorFlow). My question is not about the machine learning or Tensorflow, I want to know the best structure of the code. I ...
9
votes
1answer
152 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 ...
5
votes
2answers
70 views

Birthday paradox simulation

I'm writing a simulator which checks how many balls we need to occupy every box or how many balls we need for any box has at least 2 balls (birthday paradox). I wrote the script in python and it is so ...
5
votes
2answers
194 views

Improve Performance of Comparing two Numpy Arrays

I had a code challenge for a class I'm taking that built a NN algorithm. I got it to work but I used really basic methods for solving it. There are two 1D NP Arrays that have values 0-2 in them, ...
6
votes
1answer
118 views

Longest carbon chain

My Code measures the longest path, not allowing cycles. For the example input below, the longest chain would be 4 Please can you review my code? ...
7
votes
1answer
204 views

Deep Neural Net implementation in Python3

I created my first implementation of an arbitrary feed forward neural network with a simple back-propagation training implementation. ...
5
votes
0answers
58 views

Cubic spline interpolation in Python from scratch

I implemented the cubic spline interpolation explained in https://en.wikipedia.org/wiki/Spline_interpolation as a Python class. Of course, such an interpolation should exist already in some Python ...
3
votes
0answers
19 views

TensorFlow regressor to predict probability of winning, given a current score

This is a TensorFlow regressor that tells me that if you get x score, you will have x% to win a game in x game(game is not important). Doing this as a project to learn tensorflow. ...
0
votes
0answers
11 views

Super-minimal implementation for inference only of fully a connected neural network in Python + Numpy

There are a lot of Neural Networks Frameworks available but in order to understand how things work internally reimplementing can be a good exercise In this case the goal is to develop a super-...
3
votes
0answers
33 views

N-D Kalman Filter in Python + Numpy

Just implemented this Kalman Filter in Python + Numpy keeping the Wikipedia notation It's a pretty straightforward implementation of the original algorithm, the goals were develop skills related to ...
6
votes
1answer
160 views

Searching extreme points of polyhedron

In my Uni, my scientific professor asked me to make some researches about the extreme points of polyhedrals. And I did them. I found that there is still no code in public for searching extreme points ...
2
votes
1answer
63 views

Aggregate Pandas Columns on Geospacial Distance

I have a dataframe that has 3 columns, Latitude, Longitude and Median_Income. I need to get the average median income for all points within x km of the original point into a 4th column. I need to do ...
11
votes
1answer
1k views

Factorio analysis: data munging

This project is... a little ridiculous. It's working, but it's a complete mess. Data about Factorio's game economy are pulled from the wiki via the MediaWiki API, scrubbed, preprocessed, and thrown ...
2
votes
0answers
37 views

Compare every combination of variables within the powerset

I have some survey data that represents individual's responses to multiple survey questions. There are about 10,000 people in my actual dataset, and each person answered 35 questions. From these 35 ...
2
votes
0answers
226 views

Local maxima 3D array python

I'm trying to find the local maxima in a 3D numpy array, but I can't seem to find an easy way to do that using numpy, scipy, or anything else. For now I implemented it using ...
2
votes
1answer
29 views

Function figuring out which close-by value comes from which input value

I would like to optimize the below traceback function. This function is part of an elementary step of the program and is called a lot... ...
6
votes
1answer
69 views

Monte Carlo errors estimation routine

I would value your opinion on the following piece of code. I am rather new to both Python and Monte Carlo analysis, so I was wondering whether the routine makes sense to more experienced and ...
5
votes
1answer
331 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 ...
1
vote
0answers
38 views

Reduce memory consumption of numpy function

I have a Numpy function that takes the values of an existing array X and a size (int) k equivalent to the columns of the array. ...
8
votes
1answer
48 views

Python implementation of approximating the chance a particle is at a location after n steps in the cardinal directions

Recently, I became very interested in a probability practice problem in my textbook for my class. I decided to implement it in code and I think I got most of it implemented. Right now, I'm hoping to ...
6
votes
1answer
80 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 ...
7
votes
1answer
63 views

Extract principal components

First, I am aware that this can be done in sklearn - I'm intentionally trying to do it myself. I am trying to extract the eigenvectors from np.linalg.eig to form ...