Butterworth filters look very strange as increasing order

I’m trying to design a simple Butterworth bandpass filter in SciPy, and I’m running into some strange results. This is giving strange results, as can be seen from the image below (Butterworth filters from order 1-10). I thought the filter was supposed to become increasingly rectangular as the order increased? Does anyone know how to design a simple Butterworth filter in SciPy? Answer The frequency response of the Butterworth filter is not real-valued. When plotting the complex-valued response using plt.plot(), only the real component is shown. You should see a warning: To examine the filter’s gain, plot the magnitude of

How to use scipy.optimize.fmin with a vector instead of a scalar

When using Scipy’s fmin function, I keep encountering the error message: ValueError: setting an array element with a sequence I have seen that this question has been asked already some times, and I have read interesting posts such as: ValueError: setting an array element with a sequence Scipy optimize fmin ValueError: setting an array element with a sequence Scipy minimize fmin – problems with syntax ..and have tried implementing the suggested solutions, such as adding ‘*args’ to the cost function, appending the variables in the cost function to a list and vectorizing the variables. But nothing has worked for me

Why is ‘scipy.sparse.linalg.spilu’ less efficient than ‘scipy.linalg.lu’ for sparse matrix?

I posted this question on https://scicomp.stackexchange.com, but received no attention. As long as I get answer in one of them, I will inform in the other. I have a matrix B which is sparse and try to utilize a function scipy.sparse.linalg.spilu specialized for sparse matrix to factorize B. Could you please explain why this function is significantly less efficient than the function scipy.linalg.lu for general matrix? Thank you so much! The computation time is Answer Your matrix B is not sparse at all. More than half of the elements in B are non-zeros. Of course spilu would be less efficient

How to plot the graph obtained after using solve_ivp from scipy package to solve a set of differential equations in python

I’m using solve_ivp in python to solve a set of differential equations in state-space form.My code is as follows: It shows error while using the normal plt.plot(t,X) command. How do I plot the graph between X and t? Please help Answer It’s a bit unclear what’s being calculated here, but checking solve_ivp‘s documentation, it seems the return value (sol in this case) has a number of fields. sol.t is the list of time points. sol.y are the calculated values for each of the 4 components of X, corresponding to each value of sol.t. Here is a way to plot each

how to perform a backwards correlation/convolution in python

I am trying to perform a backwards correlation (at least that’s what I think it’s called) on 2 matrices to get a resultant matrix. Note: backwards convolution works too, because I’m applying this to a CNN. I have the following two matrices: vals: w0: I essentially want to apply a sliding window, except in this case all the values of w0 are multiplied by the scalar value at each point in vals, then added with adjacent values. Assuming a stride of 1 and a padding of same (wrt vals), the following code gives the result I want: Resulting in: Which

print chosen method of scipy.optimize.minimize

This is a short question, but google points me every time to the documentation where I can’t find the answer. I am using scipy.optimize.minimize. It works pretty good, all things are fine. I can define a method to use, but it works even if I don’t specify the method. Is there any way to get an output, which method was used? I know the result class, but the method isn’t mentioned there. Here’s an example: I could set the value method to something like slsqp or cobyla, but I want to see what the program is choosing. How can I

Python-Scipy sparse Matrices – what is A[i, j] doing?

According to my previous question here (Python – Multiply sparse matrix row with non-sparse vector by index) direct indexing of sparse matrices is not possible (at least not if you don’t want to work with the three arrays by which the sparse.csr matrix is defined, data, indices, indptr). But I just found out, that given a csr-sparse matrix A, this operation works fine and produces correct results: A[i, j]. What I also noticed: It is horribly slow, even slower than working with dense matrices. I couldn’t find any information about this indexing method so I am wondering: What exactly is

Difference between Levenberg-Marquardt-Algorithm and ODR

I was able to fit curves to a x/y dataset using peak-o-mat, as shown below. Thats a linear background and 10 lorentzian curves. Since I need to fit many similar curves I wrote a scripted fitting routine, using mpfit.py, which is a Levenberg-Marquardt-Algorithm. However the fit takes longer and, in my opinion, is less accurate than the peak-o-mat result: Starting values Fit result with fixed linear background (values for linear background taken from the peak-o-mat result) Fit result with all variables free I believe the starting values are already very close, but even with the fixed linear background, the left