Let’s say I have following dataframe contains value over time or date: I inspired from this answer to detect peaks and valleys via below code: This is the output: The problems: I can’t figure out how I can configure find_peaks() documentation to reach meaningful/drastic peaks & valley with respect to threshold as global outliers. I also checked this post but
Tag: scipy
How to prevent odeint from giving me solutions that blow up
I’m trying to solve and plot ODE using Scipy’s odeint using different initial conditions. This is done in the code below. Note that for three of the initial conditions (2, 4, and 6), the solutions die out, then the graphs start looking weird for these 3 solutions (in the plot, it’s most notable for ic/N0 = 6, which corresponds to
Python – compute average absolute difference of element and neighbors in NumPy array
I’m looking for a way to calculate the average absolute difference between neighboring elements in a NumPy array. Namely, given an array like The value for the middle square will be 2.5 (aka (4+3+2+1+1+2+3+4)/8). I know with SciPy’s correlate2d you can compute the average difference, but, as far as I know, not the average absolute difference (i.e. for the example
MATLAB freqz2 equivalent in Python
I’m trying to find a Python library that works equivalently to MATLAB’s freqz2 for image processing, since scipy.signal.freqz only seems to work for 1-D arrays. Answer Found an amazing library for plotting the 3D surface of the 2-D FFT called plotly. I leave here the lines of code I used to emulate the same behaviour of freqz2 in Python: The
Finding areas of non-overlapping edges of two distributions
I am trying to find a way to calculate the overlapping (intersection) and non-overlapping areas of two distributions. Based on some posts (like this: FINDING AREA) I could figure out how to calculate the intersection of the two plots. But I had no luck finding the non-overlapping part. Given this example distributions: I wonder how I can calculate the areas
How do I numerically integrate a string with variables in python?
Disclaimer: total noob here, please keep it as simple as possible My plan was to use scipy.integrate.quad() and eval() (code inection won’t be a problem in my case). This works fine when the only variable in the equation is the integration variable: Adding addtional variables works as long as they are defined: However if i try to give eval() those
Enhancing my code that calculates Slope Sign Change (SSC)
I am trying to code this Slope Sign Change (SSC) formula: My attempt below seems to be missing something since it generates -2 instead of 1. I am really stuck in this. Your help is highly appreciated. Answer You can compute the temporal difference with np.diff as you did: x_{n} – x_{n-1} with np.diff(x, prepend=1)[1:-1] or with slicing: x[1:-1] –
Installing scipy and scikit-learn on apple m1
The installation on the m1 chip for the following packages: Numpy 1.21.1, pandas 1.3.0, torch 1.9.0 and a few other ones works fine for me. They also seem to work properly while testing them. However when I try to install scipy or scikit-learn via pip this error appears: ERROR: Failed building wheel for numpy Failed to build numpy ERROR: Could
How to pass arguments to non-linear constraints in scipy.optimize?
I am trying to use scipy optimization to solve an optimization problem. I have defined the non-linear constraints and fitness functions as shown below in the code. I am able to pass arguments to the fitness function but not to the non-linear constraints. Is there clean way to do it? The arguments to be passed to fitness function and the
Getting the coordinates of elements in clusters without a loop in numpy
I have a 2D array, where I label clusters using the ndimage.label() function like this: I can get the element counts, the centroids or the bounding box of the labeled clusters. But I would like to also get the coordinates of each element in clusters. Something like this (the data structure doesn’t have to be like this, any data structure