Skip to main content

# Questions tagged [scipy]

SciPy is an open source library of algorithms and mathematical tools for the Python programming language.

88 questions
Filter by
Sorted by
Tagged with
-1 votes
0 answers
47 views

### handling symbolical and numerical nested integrals [closed]

I'm working on reproducing a calculation from this paper https://arxiv.org/abs/1712.03972 for my thesis but I'm struggling with how to properly implement the nested integrals in Python, specifically ...
• 107
4 votes
2 answers
138 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 ...
• 169
2 votes
1 answer
134 views

### Multithreaded sparse linear solver in Python

I would like to know if there are any multithreaded sparse linear solvers for LU decomposed sparse matrices. I want to increase the solving speed of a system like: ...
• 29
2 votes
1 answer
87 views

### "Flattening" a 2D STM image by subtracting an Nth order polynomial without typing out all the terms for each N?

I have some scanning tunneling microscopy (STM) topography images that I need to flatten. I have found that for some data I need a 4th order polynomial, but in other cases a lower order works better. ...
• 473
4 votes
2 answers
175 views

### Matrix Factorisation class packaging methods for factorisation of explicit & implicit data matrices using Gradient Descent, SGD and ALS

Attached below, and also as this GitHub gist, is code for a Python class I wrote as part of a personal learning/portfolio project on collaborative-filtering recommender systems via matrix ...
1 vote
2 answers
120 views

### Python 3.10+ deconstructing an over engineered solution to better understand how metaclasses work with properties, static methods, and classmethods

TL;DR This question examines an over-engineered example of python metaclasses and dataclasses to create a LiteralEnum (for validating a stringly-typed keyword ...
• 271
2 votes
1 answer
95 views

### Local solver built into a global one

I am trying to optimize writing a script that has 2 minimizations, one dependent on the other. My code is a bit bloated, and I find the global parameters that I am solving for depend quite strongly on ...
• 471
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 ...
• 83
1 vote
1 answer
66 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
9 votes
1 answer
4k views

...
• 99
2 votes
2 answers
1k 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 ...
• 295
2 votes
1 answer
236 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 ...
• 21
0 votes
1 answer
109 views

### Optimization using a differential evolution technique, ideally with a million iterations

I'm working on an optimization code using differential evolution to solve. However, it is taking a long time to get the solution. See that I have a variable called number_of_iterations that must equal ...
0 votes
1 answer
307 views

### Approximation of the multiplicative matrix inverse (linalg.inv ())

I am trying to compute the multiplicative inverse of a large matrix (~ >40,000x40,000). This can be done with e.g. numpy.linalg.inv or ...
• 103
1 vote
1 answer
155 views

### Calculate correlation of genes stored in dataframe rows

This script is to calculate the Spearman correlation of genes that are stored in rows of a pandas dataframe. The original df has around 2000 row names. With my current code, this requires 2000*2000 ...
• 129
5 votes
1 answer
86 views

### Rainbow Trails Video Effect

This is an effect to augment juggling videos: The goal of this effect is to add a rainbow trail to a video using a tracked set of points. Link to source video Link to source data Link to complete ...
2 votes
2 answers
1k views

### Applying Minimum Image Convention in Python

I am computing pairwise Euclidean distances for 3-D vectors representing particle positions in a periodic system. The minimum image convention is applied for each periodic boundary such that a ...
• 21
3 votes
0 answers
478 views

### Speed up interpolation in Python

I am trying to plot heatmap with three variables x, y and z, each with vector length of 932826. The time taken with the function below is 28 seconds, with a bin size of 10 on each x and y. I have been ...
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: ...
• 151
1 vote
0 answers
18 views

### LP constraint problem with scipy

For this graph and its vertex cover I try to compare the LP solution with the optimal and the rounded solution. ...
• 1,867
1 vote
1 answer
295 views

### Reduce one for loop to decrease time complexity

I'm using NumPy to find out langrage polynomial interpolation. I'm using 2 for loop to find out langrage polynomial, but I want to reduce 2nd for loop so that my code time complexity can be less. Can ...
1 vote
0 answers
252 views

### Numerical Double Integration using numba and scipy

Please see the following code. I am using it to calculate the double integration. Please help me to improve the code. ...
1 vote
1 answer
1k 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 ...
1 vote
0 answers
166 views

### Custom Model intended to be used for Curve Fitting. Vectorization vs For Loop and jit numba capabilities

I am new to community and please pardon me if I didn't provide information as intended. This code is supposed to be creating a custom model which will be used with ...
1 vote
0 answers
51 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 ...
• 111
3 votes
1 answer
288 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 ...
• 285
3 votes
1 answer
731 views

### Many parameter curve-fitting

In my project I have to make curve-fitting with a lots of parameters, so scipy curve_fit struggles to find the answer. For example: \\$\ c_0 + c_1 \cdot cos (b_0 + b_1\cdot x + b_2\cdot x^2+ b_3\cdot ...
• 285
4 votes
1 answer
644 views

### Counting Bouncy Numbers: Project Euler #113

Problem statement: Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468. Similarly if no digit is exceeded by ...
5 votes
2 answers
152 views

### A/B testing using chi-square to calculate the significance in an elegant way

The definition of ABtest Goal: For input data, each pair row is a group such as 0 and 1, 2 and 3. I want to test whether each group is significant using chi-square. If result is significant and ...
• 161
3 votes
0 answers
629 views

### Double pendulum real time plot

Double Pendulum I made a little application that embeds a matplotlib dynamic plot into tkinter that enables control through the ...
5 votes
2 answers
865 views

### Simulation of spring-loaded inverted pendulum

I've finally committed to moving to Python 3 from MATLAB. I'm currently porting my MATLAB code, and I'm sure I'm missing a lot of common best-practices. For reference, I'm simulating a spring-loaded ...
• 153
13 votes
1 answer
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 ...
• 63.1k
1 vote
0 answers
117 views

### Scipy basinhopping custom step update and constrained looping

I am searching for the global minimum of a certain function and trying to use its gradient (here same as Jacobin) to guide the step counter. However, my x is fix ...
• 241
3 votes
0 answers
2k 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 ...
• 31
6 votes
1 answer
202 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 ...
2 votes
0 answers
53 views

### Solve multi-dimentional optimization problem using basinhopping

I am searching for an optimization solution, which is a 8d vector representing 4 complex elements, where each element is within the complex circle with maximal radius 1.2. The objective function is: ...
• 241
6 votes
1 answer
411 views

### Reading sparse matrix from binary file

I have binary files containing sparse matrices. Their format is: number of rows int length of a row int column index int value float Reading ...
• 161
4 votes
1 answer
371 views

### Fast distance calculation for Starcraft2 bot

I am coding a bot for Starcraft 2, in which many distances have to be calculated every frame. Here is the part of the library that is being used and I want to improve: https://github.com/Dentosal/...
• 769
2 votes
1 answer
314 views

### Convert list of dictionaries to iterable list

Due to another module coupled to my function, I can only receive the input to my part in the form of a JSON object structured roughly like this: ...
• 123
3 votes
1 answer
90 views

### Simple natural language classifier

This program estimates the likelihood for a string to belong to a certain natural language by computing the cosine similarity between an input string's and several natural languages' letter frequency, ...
• 33
6 votes
1 answer
2k views

### Spearman correlations between Numpy array and every Pandas DataFrame row

I want to efficiently calculate Spearman correlations between a Numpy array and every Pandas DataFrame row: ...
2 votes
1 answer
83 views

### Implement metaclass for Maximumlikelihood estimator

For the purpose of defining a lot of Maximum Likelihood estimators, I think I need a metaclass. At the moment I have to copy/paste a lot of code for every new class definition and just substitute the ...
• 944
2 votes
1 answer
105 views

### Grade of Service Probability Function Python

Consider the following typical probability scenario: I defined this function to handle that scenario, I'm curious if Python has a more efficient method to handle this, or if this is the best way: <...
• 247
7 votes
1 answer
679 views

### 2d linear Partial Differential Equation Solver using finite differences

This is code that solves partial differential equations on a rectangular domain using partial differences. fd_solve takes an equation, a partially filled in output, ...
• 3,597
1 vote
1 answer
203 views

### Ensuring performance of sketching/streaming algorithm (countSketch) [closed]

I have implemented what is know as a countSketch in Python (page 17: https://arxiv.org/pdf/1411.4357.pdf) but my implementation is currently lacking in performance. The algorithm is to compute the ...
• 19
7 votes
2 answers
645 views

### Calculate electric field of a charged annulus

This script calculates the shape of the electric field on a 2D grid perpendicular to a uniformly charged annulus using SciPy's dblquad (tutorial, documentation). I'...
• 473
1 vote
0 answers
7k views

### Fuzzy c Means in Python

This is my implementation of Fuzzy c-Means in Python. In the main section of the code, I compared the time it takes with the sklearn implementation of kMeans. ...
• 195
5 votes
1 answer
310 views

### Probability of event using Central Limit Theorem + plotting results

I've been doing a Udemy course called: "Statistics for Data Science" and I decided to solve one of the homework with Python to kill two birds with one rocket #elon. The task was: The team of ...
4 votes
1 answer
482 views

### kNN with Python

I'm writing a k nearest neighbors implementation to solve multiclass classification. ...
• 926
3 votes
0 answers
571 views

### Compute distance matrix using DTW acceptable for scipy.cluster.hierarchy

I am new to both data science and python. I have a dataset of the time-dependent samples, which I want to run agglomerative hierarchical clustering on them. I have found that Dynamic Time Warping (DTW)...
• 211