Questions tagged [numpy]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
8 views

Fast way to calculate Standing Wave modes in NumPy

I am trying to plot the standing wave modes in a 2D box over time. The equation for this is: $$ A(x,y,t) = \sum\limits_{n,m} sin \left( \frac{n \pi x}{L_x} \right) sin \left( \frac{m \pi y}{L_y} \...
1
vote
1answer
23 views

What would be the computationally faster way to implement this 2D numerical integration?

I am interested in doing a 2D numerical integration. Right now I am using the scipy.integrate.dblquad but it is very slow. Please see the code below. My need is to ...
4
votes
1answer
66 views

Code for wireless communication work

I need some pointers on how I can speed up my code, as of now it is incredible slow for larger inputs. The way the code works is that the file Loc_Circle_50U.txt contains the true locations of 50 ...
-2
votes
0answers
50 views

Python Virus Spread Simulation with Markov Chain Random Walking [closed]

So in the light of the current situation and because of a home lockdown in my country I decided to try myself in a simple SIR Model Simulation in which I create a simple world with people who could be ...
5
votes
3answers
485 views

Improvement on data normalization

I have a part of code that is loading a dataset and normalizing property values to [0, 1]. My implementation is: ...
3
votes
1answer
71 views

Building optimal portfolios for all combinations of stocks

Hi I recently wrote some code in python that does the following: 1.) Pulls stock closing data from yahoo finance for x number of stock 2.) finds all possible combinations of x stocks in groups of y ...
4
votes
1answer
100 views

Can this sampling code be vectorized or optimized?

I have some code that is slow because it loops over every row in an input matrix Y. Obviously, this code does not scale with the number of rows. I don't think it's ...
6
votes
1answer
52 views

Binning whilst avoiding the need for for-loops in Python?

I am working on a relatively simple binning program, where I take a 5D array and bin it based on two 3D arrays to create a contour plot. See the sample code below. In actuality, my arrays are of size <...
4
votes
1answer
72 views

How to stop a Python script if the input values do not make sense within the environment in which they will be analyzed?

I am not a developer, but I needed to write a script. So I wrote it. Since I can't find an accessible tool that fulfills the same purpose, which I think may be helpful to others, I decided to ...
3
votes
0answers
48 views

Clean and fast MiniMax for numpy implementation of Tic-Tac-Toe

Tic-tac-toe is small enough to be solved completely but since I have a slow computer and this is an interesting exercise, I want to build the fastest possible minimax tic-tac-toe implementation in ...
2
votes
0answers
35 views

Convoluting 3D image with 2D

I have a single image of shape img.shape = (500, 439, 3) The convolution function is ...
2
votes
1answer
171 views

AI In 2048 Game, Calculations so slow

Inspired by this answer on stackoverflow for AI implementation in 2048 game. I have been trying to make AI calculate best move by playing the game given specific times in memory preceding by one ...
-1
votes
1answer
43 views

Trying to get every 6th set of 4 bytes from a python array [closed]

I have an array of bytes 6144 bytes long. I want to extract a set of 4 bytes every 6th set of 4 bytes . So every 24 bytes I want to extract 4 of those bytes and join them in a new array. So ...
2
votes
1answer
54 views

Forecasting stock market data using Support Vector Regression

I coded this Support Vector Regression (SVR) myself following some equations in a journal (see here, or here (not in English)). The loss function used by the journal and the code below is mean ...
0
votes
0answers
22 views

Sequential learning function running slowly

I'm new to Python and made this Sequential Learning function but it runs slowly. Do you know why this runs slowly and how to improve it? ...
5
votes
2answers
130 views

Loop through group and difference lags

I have time-series data (t) that I want to loop through each t and take the difference of the previous five lags ...
2
votes
1answer
65 views

Asteroids using pygame

I made the looks of asteroids using pygame. I still need to implement collisions but since it is running incredibly slow with 'amount' anything above 10. Please rip ...
1
vote
0answers
35 views

Python Implementation of Canopy Structural Dynamic Model using scipy.optimize.least_squares

I am using the least_squares() function from the scipy.optimize module to calibrate a Canopy structural dynamic model (CSDM). The calibrated model is then used to predict leaf area index (lai) based ...
7
votes
2answers
164 views

Find the closest enemy in a 2D grid with wrapping allowed

I'd like feedback on my solution to the outlined programming challenge. Is numpy a good candidate module for this? What might be a more efficient or Pythonic solution? Closest Enemy II Have ...
10
votes
2answers
1k views

Generating large testing datasets

I have made a small Python script that will generate some test sets for my project. The script generates 2 datasets with the same dimensions n*m. One contains ...
1
vote
1answer
97 views

Vectorize pairwise edit distance computation [closed]

How can I vectorize this function? It takes an array of array of tuples as input and computes the distance between elements using Levenshtein's method. I found some simpler examples but they weren't ...
7
votes
0answers
144 views

Multithreaded HD Image Processing + Logistic reg. Classifier + Visualization

[I'm awaiting suggestions for improvement/optimization/more speed/general feedback ...] This code takes a label and a folder path of subfolders as input that have certain labels ex: trees, cats with ...
4
votes
1answer
46 views

Move values to back of an np.array()

I'm trying to create the most efficient (not nicest/prettiest) way of moving particular values within an np.array() to the back of said array. I currently have two different solutions: ...
1
vote
1answer
37 views

Optimization fo code snippet including multiple np.multipy statements

I working on optimizing some code for speed in a python module. I have pinned down the bottleneck and is a code snippet which calculates three np.ndarrays. Namely ...
7
votes
0answers
74 views

Calculation of independence test statistic

This code (~30lines) detects independence between variables in a dataset, by using a bootstrap of a statistic. This is fully-broadcasted, but it's still long. Reading it, or making it run, do you ...
4
votes
2answers
84 views

First program in Python for data analysis

I'm just starting my adventure with python and I wanted to share my first project with you and ask for feedback and advice. This is a script for my friend to automate all calculations and database ...
3
votes
1answer
90 views

improving speed of this numpy-based diffraction calculator

I'm going to simulate diffraction patterns of a normal incident gaussian profile beam from a 2D array of point scatterers with a distribution in heights. The 2D array of scatterer positions ...
2
votes
0answers
44 views

Generate Black and White confidence map masks for joints, same as OpenPose/Convolutional Pose Machines

Attached below is my code for generating the confidence maps for the joint locations, it is in the same vein as the maps generated for the paper Convolutional Pose Machines and OpenPose. I am ...
1
vote
1answer
63 views

Optimize option pricing code

I am new to Python and am trying to optimize the following code: ...
2
votes
1answer
65 views

I need to process a list of already-tokenized sentences into skipgram samples. How do I do this efficiently?

I have a customized function to accomplish the business requirement I mentioned, but this one takes a very long time to run. I was wondering if there was any way to shorten that time? ...
1
vote
0answers
22 views

DataSet Scaler with pandas

This is a Python program that takes data from Quandl Databases and formats it for my Neural Network to Train. The code works but I'm not so confident in my code styling conventions. If you would like ...
3
votes
1answer
81 views

N-Body Gravitational Simulation of Point-Masses in Python

I made an n-body gravitational simulation in python. The algorithm does produce an approximate solution, which is shown at the bottom of the post. Additional methods to produce animations (among other ...
8
votes
3answers
629 views

Modifying Titration Data analysis results

This is my first script that I've written. As a result, I'm sure there are extra lines that are unneeded, or maybe better more concise ways of doing things than I have done here. I have tried to add ...
6
votes
2answers
153 views

A Neural Network

I programmed a Neural Network in python. Feedback every kind is appreciated. I tried to use some vectorization but it turned out to become quite a mess. Because you can't append to numpy arrays I ...
6
votes
1answer
246 views

Dealing with lot of images and multiplications

With some basic knowledge of Python and referring a lot of sources, I have written the code below. But it takes half an hour for execution. How can I reduce the time? I read about vectorization but ...
5
votes
1answer
143 views

process numerical input arguments of mixed ints, floats, and “array-like” things of same length>1

I'm trying to process numerical input arguments for a function. Users can mix ints, floats, and "array-like" things of ints and float, as long as they are all length=1 or the same length>1. Now I ...
8
votes
3answers
708 views

Creating an affinity-matrix between protein and RNA sequences

I wrote an algorithm that analyzes protein-RNA interactions and I found that the following function is the bottleneck that causes performance issues: ...
4
votes
1answer
33 views

Save points cloud in PLOT3D format

I have the following function to save points cloud in PLOT3D format: ...
5
votes
1answer
148 views

Remove words from an exclude list in each row of a pandas.Series

I am trying to remove all occurrences of the words I collect in the list exclude from every text note. This is my approach. ...
8
votes
1answer
452 views

Optimize Performance of Region Checking in List Comprehension

I am modeling a linear process at a number of equally spaced time steps. I have a large list (~70k elements) which corresponds to a location at each time step, ...
4
votes
0answers
44 views

Importer for binary datafile of PI88 Nanoindenter

As an exercise, I want to rewrite a C++ program to import measurement files (and later create excelsheets, reports ...). The measurement files split in 2 files, a binary file, and a xml-file. Because ...
5
votes
2answers
90 views

Back to Basics: Tic Tac Toe - follow-up

Follow-up from: Back to Basics - Tic Tac Toe Again, any optimizations and critique is welcome! I'm particularly interested if it involves numpy, ...
3
votes
1answer
1k views

Minimax algorithm for tic tac toe in Python

I am using minimax algorithm (for now without alpha beta pruning) for AI in tic tac toe game in Python and Numpy. It's working, but very slow, so I would like to optimize it. A few rules for current ...
4
votes
1answer
72 views

Back to Basics - Tic Tac Toe

I've seen a few TTT related posts recently, and thought I might learn something or be reminded of certain techniques from attempting my own rendition. Here is that attempt! Hopefully any new coders ...
5
votes
1answer
135 views

Implementing 3Blue1Brown's description of Fourier transform in Python+numpy

I have implemented the 3Blue1Brown's description of Fourier transform in Python+numpy for irregular and unsorted data, as described here. ...
1
vote
0answers
90 views

A python script to plot a joint probability mass function table [closed]

Consider this example Suppose that 3 balls are randomly selected from an urn containing 3 red, 4 white, and 5 blue balls. If we let X and Y denote, respectively, the number of red and white ...
1
vote
1answer
119 views

Remove outliers from N dimensional data

I have created a function that will remove outliers from a series of data. Generally the data n dimensional. Loosely, an outlier is considered an outlier if it +/- deviates by 1.5 standard_deviation's ...
3
votes
1answer
106 views

Optical dispersion calculation from spectrograms with Python

First, I'd like to provide a little explanation on what my code is supposed to do. It is part of a middle-sized project. I restructured the code to work on its own, and also added little comments to ...
2
votes
1answer
51 views

K_nearest_neighbors from scratch [closed]

I wanted to create a script that will perform the k_nearest_neighbors algorithm on the well-known iris dataset. This was mainly for me to better understand the algorithm and process. I think it works, ...
5
votes
1answer
106 views

State space search for sliding tile puzzle

I am working on state space search (8 Puzzle) in Python and when I run my program with python3 -m profile, I find out that most of time program performs a few ...

1
2 3 4 5
12