All Questions

Tagged with
Filter by
Sorted by
Tagged with
8 votes
2 answers
385 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 ...
  • 83
1 vote
1 answer
25 views

Fixing math library functions in Black-Scholes options pricing model

I've amended a code for the Black-Scholes formula for European pricing options found here at the bottom of the page and fixed the math functions accordingly. Unlike the code on the website, mine has ...
  • 113
1 vote
1 answer
121 views

Unpythonic matrix manipulation

This code does exactly what I want it to, however I want to try and get rid of the nested loop to make it more pythonic. I have been trying to somehow use broadcasting, including playing with ...
3 votes
1 answer
104 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 ...
  • 121
3 votes
0 answers
102 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
42 views

Further optimizing the ISING model

I've implemented the 2D ISING model in Python, using NumPy and Numba's JIT: ...
2 votes
2 answers
193 views

Poker hand valuator in Python

As you will probably notice very quickly from the code below, I'm not very experienced coder. Below is my attempt at valuating poker hands in Python. The code below may not be pretty but it seems to ...
2 votes
2 answers
71 views

pixelating images

I'm a hobby programer and I had an idea for pixelating images and I wrote it. I was wondering how would a better programer write the same function. I want to learn and I think that this would help me ...
9 votes
1 answer
3k views

Python decibel meter-accurate?

...
  • 99
1 vote
1 answer
66 views

How to using custom colormap with pixel calculation, gray scale value by opencv and make it workable on camera [closed]

I tried to implement the mcolor colormap in the paper at page 8 to 10. I developed the code to process a image file and it works ok. Now, I want to adopt this image processing method to the camera ...
3 votes
1 answer
65 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: ...
  • 133
1 vote
1 answer
161 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 ...
  • 111
3 votes
1 answer
131 views

Generating random number of randomly sized Squares/Rectangles using numpy arrays

I made classes to use in generating square/rectangular shapes on a texture. ...
  • 31
1 vote
0 answers
34 views

BoundingBox dataclass implementation with cupy, cudf, and nvector

The dataset I'm working with is rather large so I've been experimenting with cudf and cupy. Here you can find instructions for ...
3 votes
2 answers
172 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 ...
  • 177
1 vote
1 answer
36 views

Plotting determinant probabilities

This is a fun exercise that tries to answer the following question: if the elements from a square matrix are randomly chosen from 0 to 9, is it more like that the determinant would be even or odd? I'm ...
0 votes
0 answers
28 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: ...
  • 61
4 votes
1 answer
63 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) ...
  • 143
13 votes
3 answers
1k views

Looking for the particles that are emitted when a fish is detected in Terraria

The code run perfectly fine, with no errors. However, the entirety of the code is in 1 function and is kind of hard to read. As well as that I'm not sure if and how the code could be more optimised/...
2 votes
2 answers
437 views

Solving the TDoA multilateration problem in 3-dimensions

Background. I've written an algorithm to solve the Time Difference of Arrival (TDoA) multilateration problem in 3-dimensions. That is, given the known coordinates of ...
  • 285
3 votes
1 answer
48 views

Simulate a population of agents and compute averaged cumulative efficiency

I have the following code which is a model where each agent makes decisions and accumulates efficiency over time. With the def scenario function, the idea is to ...
  • 163
2 votes
0 answers
72 views

Do Mann-Kendall and Pettitt tests on each CSV file

Here is a function that will take each text file in a directory, do the Mann-Kendall and Pettitt tests, and then write the output to a text file. Would you please suggest me improve the code to make ...
2 votes
1 answer
109 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): ...
  • 123
2 votes
1 answer
143 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
62 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 ...
  • 177
0 votes
0 answers
109 views

Python image triangular mosaic creator

This is a Python script that turns images into "low-poly" art/creates a triangular mosaic from the image, I wrote this script completely by myself. In short, it takes a filepath to an image, ...
0 votes
0 answers
58 views

Deep Reinforcement Learning training on gym data

Related question: Extract the last row in a dataframe with a timestamp before some given time This is part of the code for Deep Reinforcement Learning training on a standards-based gym env. What I ...
  • 177
-1 votes
1 answer
36 views

Numpy way of selecting indices of 2D numpy array if a condition met [closed]

I have a snippet of code to get indices of a 2D numpy array if the maximum value of that raw is greater than a number. ...
1 vote
0 answers
107 views

A collection of Python functions that fill a given region with rectangles

These are what I was working on in the last few days, I wrote a bunch of functions that fill a given region with rectangles of different colors. The functions can: Randomly split a region into sub ...
0 votes
0 answers
46 views

Python function that skews an image while preserving its aspect ratio using affine transformation

See this post for more details. I re-implemented my idea using affine transformations, and finally understood how transformation matrices are formed... Turns out it is stupidly simple, but nothing I ...
3 votes
1 answer
478 views

Python function that shears image by n degrees while keeping the relationship between height and width

I am trying to find a method to shear/skew an image horizontally or vertically by n degrees (n ranges from -90 to 90 excluding the terminals) so that the result would meet the following conditions: ...
2 votes
2 answers
62 views

Sampling from k circles with different radii

Description: I would like to sample n_points points from k circles whose radii and centers are given as lists. Note: This is my ...
0 votes
0 answers
70 views

Python 3 OpenCV script that scans a giant picture to make a video

This is a Python script that I wrote completely by myself. Basically it scans a giant picture to make a video. They say one picture is worth more than a thousand words. Since a video contains ...
0 votes
1 answer
219 views

Extract all elements of array with the given list of coordinates [duplicate]

I have to extract all elements of array with the given list of coordinates and insert into 2*298808 as position given in while loop How can I compress the code even more? ...
  • 5
-1 votes
1 answer
75 views

How can i refactor python numpy code? [closed]

...
  • 5
0 votes
0 answers
32 views

Creating an image from data, and slicing it into zxy tile service

I have some data that comes out of a grib file. The values in the grib file come out in shape of (721, 1440). Each value ...
0 votes
1 answer
67 views

Stacking Z axis on multiple [1440x720] DataFrames (X, Y)

Each datum represents a point in a 1440x720 image of the globe, The values are 0-9. Each new layer is of a higher elevation. I need to structure a DataFrame in a ...
6 votes
1 answer
928 views

Python 3 script to make photo collages

I have written a Python script that takes a list of filenames of pictures and generates a photo collage of them. This is my most complex project yet, and I have written it completely by myself (like I ...
3 votes
1 answer
193 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 ...
  • 121
2 votes
1 answer
121 views

type hinting/documenting/extension of a Cython lib

I've updated some of the type hinting/documentation in a lib called pygrib. The source documentation can be found here. The goal is to extend the ...
1 vote
1 answer
142 views

Solving a 3D heat diffusion PDE

I am trying to solve a heat diffusion type PDE using a finite difference method. I would like to preface that I have seriously simplified the code. Just so that anyone who tries to help me, doesn't ...
  • 121
2 votes
1 answer
72 views

dataframe mean outliers to NaN to derive a higher quality mean for area,speed,azimuth

I have some data that represents the area, speed(meters per second), and azimuth(rads) of a polygon. The objective is to determine the mean for each set of parameters. With that mean value, apply a ...
1 vote
1 answer
49 views

numpy mean azimuth with functools.reduce

From the left to the right column calculating the mean azimuth, and using that mean value to calculate the subsequent columns mean value data (azimuth radians) ...
3 votes
1 answer
71 views

Making a list of shades and styles for plots

For a section of a much larger program that generates plots, I am creating a list of styles that I can pull from to create a consistent format from plot-to-plot. It works as follows I have a list of ...
  • 133
3 votes
1 answer
311 views

Vincenty's distance Direct formulae numpy

I've refactored a function from the pygc library used to generate the great_circle. The Vincenty's equation below can be found ...
3 votes
1 answer
152 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{...
4 votes
1 answer
82 views

3D to 4D surface fitter converter

I recently wrote this bit of code while trying to convert a 3D surface fitter to a 4D one. The solution works and I didn't want to leave the next guy to grind out the solution so I made the code as ...
1 vote
0 answers
43 views

Pandas Numpy Nvector to generate a storm track algorithm

I made previous post here, relating to this topic. The class uses now uses some additional 3rd party libs nvector & pygc. ...
1 vote
1 answer
97 views

Multiple GeoJSON Feature Collections to a Pandas MultiIndex DataFrame

Edit: The end objective is to monitor the movement of severe weather, determine its vector and make a prediction. I'm working with a GeoJSON ...
5 votes
1 answer
648 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
2 3 4 5
15