Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [numpy]

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

0
votes
0answers
27 views

Cleaning words from numpy arrays [on hold]

I'm a new joiner in a software engineering team and have been given this code for refactoring. This code feels very gluey and dependent to me but I can't decide how to make it independent. This is ...
6
votes
2answers
73 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
0answers
25 views

Loop on dataframe takes a lot of time [closed]

The dataframe subset feature is being used in a for loop across the dataframe rows. The result seems accurate however, the time taken to complete the loop on 2000 odd rows is more than 4 minutes. Any ...
2
votes
1answer
42 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
100 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
38 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
85 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
42 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
52 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
50 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
46 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
75 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
40 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
158 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
50 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
150 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
63 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
193 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
203 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
49 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
15 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
31 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
154 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
48 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
180 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
68 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
319 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
34 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
74 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 ...
2
votes
1answer
42 views

Calculating the potential of a matrix of size (424600, 55)

I have the following working code to calculate the potential of a matrix after normalizing the matrix. But it is too much time consuming. Is there a way to make this code run faster? ...
0
votes
0answers
41 views

Counting events that occur in some time intervals

I have a python code where I need to count the number of ids in a given range of timestamps as : ...
1
vote
0answers
32 views

How to speed up the retrieval of the corners of a mask

I have trained a polygon detector neural network to recognize the mask of "quadrilateral" (the mask generates curvy lines so it's not exactly a quadrilateral). I would like to get the corners of the ...
1
vote
1answer
98 views

Vectorized N-Dimensional Random Walk in Cartesian Coordinates

I have written a random-walk routine that I hope to build upon in the future. Before doing so, I was hoping to get some critique. I believe the implementation is correct. I noticed that many other ...
2
votes
1answer
159 views

Inverse mapping with bilinear interpolation on an image

The following is my solution for an inverse mapping with bilinear interpolation on an image. The original image is img and ...
5
votes
1answer
63 views

Code to plot graphs with multiple panels efficiently

I quite often plot graphs looking at how some property or function varies with different parameters. Normally, I find the analysis code can be written fairly succinctly and separated into a suitable ...
3
votes
0answers
54 views

Locality Sensitive Hash (similar to k-Nearest Neighbor), in Python+Numpy

I've tried implementing Locality Sensitive Hash, the algorithm that helps recommendation engines, and powers apps like Shazzam that can identify songs you heard at restaurants. LSH is supposed to run ...
3
votes
1answer
191 views

Image pre-processing and segmentation

I'm new learning python and image processing with python. For this reason, I took a project called "Classification of breast cancer images with deep learning". I applied the following techniques: 1)...
3
votes
0answers
49 views

Computing Doppler delay on a meshgrid

Objective Plot the contour of the iso-doppler and iso-delay lines for a transmitter-receiver reflection on a specular plane. Implementation This Doppler shift can be expressed as follows: $$f_{D,0}(...
1
vote
1answer
44 views

Plot a piecewise-defined function

I would like to plot the following function: $$ \begin{align} \Lambda(\delta\tau) &\equiv\ \chi(\delta\tau, 0) = \frac{1}{T_i} \int_0^{T_i} a(t_0+t')a(t_0+t'+\delta\tau) dt' \\ &= \begin{...
6
votes
1answer
60 views

Optimal algorithm to move a a rope from one position to another

I'm an engineer working with a deformable membrane that is attached to actuators. The goal is to move the membrane from one shape to another, without ripping the membrane. This imposes "neighbor ...
4
votes
1answer
50 views

Set of one-hot encoders in Python

In the absence of feature-complete and easy-to-use one-hot encoders in the Python ecosystem I've made a set of my own. This is intended to be a small library, so I want to make sure it's as clear and ...
3
votes
0answers
55 views

Minimization problem solving and its step limits

I am trying to solve the following minimization problem: $$ \min\lvert\lvert{x}\rvert\rvert_1 + \beta\lvert\lvert{x}\rvert\rvert^2_2 s.t. \sum_{m = 1}^M (y - \lvert{c}^{H} . x\rvert^2)^2 \le \epsilon ...
2
votes
2answers
41 views

Compare an array with a file and form groups from elements of an array

I have a text file with letters (tab delimited), and a numpy array (obj) with a few letters (single row). The text file has rows with different numbers of columns. ...