All Questions
Tagged with performance numpy
239
questions
4
votes
2
answers
108
views
Srivastava multivariate Fox H function in MATLAB
I was trying to rewrite the Python code in MATLAB.
The result is consistent.
But, the MATLAB code is so slow. Any help would be appreciated.
Ref python code link
The MATLAB code written by me is as ...
3
votes
5
answers
1k
views
How do I speed up this simulation program
This is a program to solve a differential equation numerically using Euler method. As of now, it is very slow, and I need to run 10000 Monte Carlo simulations.
The differential equation is called ...
4
votes
2
answers
166
views
NumPy script to convert BGR to HSL and back
This is a NumPy script that converts BGR arrays to HSL arrays and back, without using OpenCV. Input and output values are arrays of 3 dimensions with values ranging from 0 to 1, the shape of the ...
5
votes
1
answer
82
views
Generating Abelian sandpile "zeros" in python
Here is some code that generates the zero element of an Abelian sandpile model (ASM), for any given model dimensions, and then plots the result as a colormesh. Here is a wiki page explaining the ASM. ...
0
votes
1
answer
207
views
Find the first value bigger than a threshold
This function takes two inputs: A is 2D (N,5) while B is 1D (N).
It tries to find the smallest ...
2
votes
1
answer
179
views
Is this the right implementation for Linear Programming (puLP) on python?
I have created a LP function to help maximize a set of features. My first time playing with this library and also conducting LP.
Variables:
Number of features => X
Number of Categories => Y
...
6
votes
1
answer
135
views
basic Hartee-Fock program to compute the total energies and some properties of a molecule
I am trying to write a basic Hartee-Fock program that computes the total energies and some properties of a molecule given as an input. The code uses Cython to statically compile the computationally ...
6
votes
2
answers
482
views
Means square displacement (MSD)
I have written a code to calculate the MSD of some molecules. The code averages over multiple time origins (sliding time window) and over all the molecules. I have also made it do one extra thing: do ...
8
votes
2
answers
525
views
Fourier Series of a given function
This is a very simple code that expresses a function in terms of Trigonometric Fourier Series and generates a animation based on the harmonics. I would like to know some ways to improve the ...
3
votes
1
answer
161
views
Solve an option pricing PDE in Python - Part 1 [closed]
The Github repository NM-Heston solves call option prices under the Heston 2-factor model using ADI splitting schemes. I am adapting the code to price options under the 3-factor Heston-Hull-White ...
3
votes
0
answers
103
views
E-car-sharing problem with charging between the bookings
I am writing code that, at some later point, will be part of an academic multi-agent simulation of the learning process of car-sharing users and grid stability. This code deals with finding the price ...
1
vote
1
answer
136
views
Further optimizing the ISING model
I've implemented the 2D ISING model in Python, using NumPy and Numba's JIT:
...
3
votes
1
answer
118
views
Create a forecast matrix from time series samples
I would like to create a matrix of delay from a time series.
For example, given
y = [y_0, y_1, y_2, ..., y_N] and W = 5
I need to create this matrix:
...
1
vote
1
answer
499
views
Create normals from triangulated surface
Objective
I have a 3D face mesh triangulated. I have computed the midpoint of each triangle in the mesh, and I have the normal vector (n1, n2,n3) for each triangle. The objective is to create a 2D ...
3
votes
2
answers
195
views
Intercolumn statistics between columns in a dataframe
I have a df and need to count how many adjacent columns have the same sign as other columns based on the sign of the first column, and multiply by the sign of the ...
0
votes
0
answers
140
views
Algorithm to generate splats from point clouds
I am trying to write a program to generate splats from point clouds from following this paper and this paper.
The function I have to generate 1 splat is here:
...
4
votes
1
answer
75
views
Optimising compatibility-conflict graph solution - python recursive routine
Background
I'm implementing an algorithm which localises overlapping sound sources using the time-difference-of-arrivals across 3 sensors [1]. Compatible 'triples' (e.g. with only 2 common sensors) ...
2
votes
1
answer
412
views
Improving the speed of one-hot encoding a list of strings
I've recently developed two functions to functions to essentially convert a list of strings that look something like this (these strings are 101 characters long in my case):
...
2
votes
1
answer
235
views
Integration loop over multiple doping and temperature levels
I want to perform some calculations on a large dataset. The code can be found below, where I want to calculate the values for 'results_nr' over a large loop (1000 x 910) values. Can you help me out ...
1
vote
1
answer
75
views
Generate new column based on two columns of dataframe
I need to generate column a_b based on column a and column b of ...
2
votes
1
answer
255
views
Replace nested for loops when assigning intial conditions in a 4-dimensional array
I create a 4-dimensional (x, y, z, t) array of zero values. I then set the initial values at t = Tmax. To do this, I use a nested for loop. I attempted to improve ...
3
votes
1
answer
206
views
Numerical integration in Python involving four dimensions
I'm trying to obtain the following S2 from a given S1,
$$
S2(i, j) =
\sum _{k=0} ^i
\sum _{l=0} ^j
S1(k, i-k, j, l)
e^{
-\sqrt{...
5
votes
1
answer
929
views
Laser physics simulation
This is for a computation for laser physics. The speed is quite slow, which seems to be delayed a lot by the three nested for loops with indices j,k, and l (with comments below). And the computation ...
1
vote
1
answer
700
views
Exponentially-weighted moving mean and standard deviation of an irregularly-spaced weighted time series
The following numpy/python function computes exponentially-weighted moving mean and standard deviation of an irregularly-spaced weighted time series. I want to make it faster by getting rid of the ...
1
vote
0
answers
128
views
Solving a linear system with Gaussian Elimination
I decided to implement a solver for linear systems of equations based on the gaussian elimination and reduction to upper triangular form. The gaussian elimination is quite simple to implement but the ...
4
votes
3
answers
411
views
Pairwise Euclidean distance search algorithm
x and y are two-dimensional arrays with dimensions (AxN) and (BxN), i.e. they have the same number of columns.
I need to get a matrix of Euclidean distances between each pair of rows from x and y.
I ...
2
votes
1
answer
208
views
Generating a matrix with each row having normalized weights
I just asked this question over Stack Over Flow on how to improve my code and reposting it here as someone on Stack Overflow recommended this platform.
I have written two python functions and they are ...
3
votes
0
answers
66
views
Implementation of a crypto formula in Python
I need to implement in Python the formula in the image. The set B is a set of real numbers \$-1 \le t \le 1\$. Also, \$\mathbb{F}_2\$ is a set with the elements 0 and 1. \$y_i\$ is the \$i\$-th ...
2
votes
0
answers
139
views
Convolution layer using numpy in python
I'm trying to make a CNN in python using numpy. I have a finished product but it seems that it can be improved. On testing the convolutional layer is the biggest bottleneck
...
1
vote
0
answers
157
views
Computing the angle between two vectors (vectorized) for small angles and with few copies
I am implementing a function that computes the angle between two vectors when given two n-dimensional arrays and an axis along which to operate. I want to do this with as few copies as possible, and ...
4
votes
1
answer
104
views
Dataframe transformation to numpy ndarray takes ages to complete
I would like to transform my dataframe into an array of fixed-sized chunks from each unique segment. Specifically, I would like to transform the ...
2
votes
1
answer
47
views
Removing Loop from Numpy XOR
I have been playing around with numpy and matplotlib.
My little project was to create a scatter plot ranging from -1 to 1 on both X and Y, but where the shading is done with the XOR scheme.
The ...
3
votes
1
answer
820
views
Using Numba works slower than not using it for my Python code
I thought this community is better place to ask my question so I ask here rather than at StackOverflow.
Recently, I learned that Numba can make Python function ...
10
votes
1
answer
329
views
From Hummingbirds to Ornithopters: Simulating the Aerodynamics of Flapping Wings
Ptera Software
A Flapping Wing Aerodynamics Simulator Written in Python
Motivation
About a year ago, I became fascinated by how animals fly. As an aerospace engineering student, it surprised me that ...
2
votes
1
answer
1k
views
Fast brute force numpy array combination
I want to extract the combinations of numpy arrays in this way:
...
2
votes
1
answer
98
views
Performance issue in python- network creation based on the Euclidean distance with nested for loops is too slow
I want to create a network in which the links are formed based on a similarity metric defined as the Euclidean distance between the nodes. The distance is calculated using socio-demographic features ...
1
vote
1
answer
104
views
decreasing solver speed
How can I decrease the time complexity and increase efficiency, without writing a new algorithm. My solution solves the majority of puzzles in a fast time, but for some difficult ones it can take over ...
5
votes
1
answer
202
views
compare between two labels /objects -dominance rules
I have a function dominates() that seems to be the bottleneck of my algorithm (after profiling it). the function is as follows:
...
3
votes
1
answer
157
views
Snake from the viewpoint of the snake
I wrote a little game of snake that where you can see the field in which the snake moves fixed and you can also see the "viewpoint" of the snake, which is basically calculating the positions ...
4
votes
1
answer
134
views
Neural Network Written in Python is Extremely Slow
I coded a basic feedforward neural network with all pure python with the exception of numpy in order to better understand how neural networks work. It works, but the only problem is it is extremely ...
1
vote
0
answers
49
views
Resource reservation system
I'm using a function to determine if resources can be used again or not.
This is the numpy array I'm using.
...
5
votes
1
answer
433
views
Bancroft's method implementation
Background
I've written an algorithm to solve the three-dimensional Time Difference of Arrival (TDoA) multi-lateration problem. That is, given the coordinates of n ...
4
votes
2
answers
4k
views
Cython with variable-length arrays
Dynamically growing arrays are a type of array. They are very useful when you don't know the exact size of the array at design time. First you need to define an initial number of elements. (Wikipedia)
...
1
vote
1
answer
42
views
Pandas : Apply Merge operations from a column
I have a data frame, which contains three columns:
...
1
vote
2
answers
188
views
Better way to calculate double-scattering diffraction using cartesian product of arrays?
This script calculates points in reciprocal space for hexagonal 2D lattices, then uses the cartesian product from itertools to add each vector from one lattice to all of the vectors of the other in ...
6
votes
1
answer
124
views
Code optimisation: Converting dataframe to numpy's ndarray
I am working with a dataframe of over 21M rows.
...
1
vote
1
answer
2k
views
Count the number of neighbors
I have a numpy array called contour of \$N\$ coordinates (x,y) of dimension (N, 2).
For each ...
1
vote
1
answer
111
views
Getting the square of the difference between many points in a NumPy array
I have an array with 40000 numbers that are floats or ints. I need to perform some calculation.
To do this I have used nested for loop, but the code is really slow. Can I use something instead of ...
4
votes
1
answer
286
views
Generating unique 2D numpy arrays with 2 adjacent row elements swapped while using BFS in Python
So I have a 12 x 6 2D numpy array for input which consists of 7 possible board objects (characters from 'abcdefg'). From a 2D numpy array I wish to generate all the possible unique 2D arrays, in whose ...
0
votes
1
answer
526
views
Image color-moment extractor [closed]
I was just wondering if there is a way to speed up the performances of this for loops in Python.
I'm trying to process an image to get the color-moments without using libraries.
It takes about 12sec ...