scipy

Scipy ndimage.convolve skips the summation of channels

旧时模样 提交于 2021-02-05 08:37:10
问题 I'm trying to use scipy 's ndimage.convolve function to perform a convolution on a 3 dimensional image (RGB, width, height). Taking a look here: It is clear to see that for any input, each kernel/filter should only ever have an output of NxN , with strictly a depth of 1. This is a problem with scipy , as when you do ndimage.convolve with an input of size (3, 5, 5) and a filter/kernel of size (3, 3, 3) , the result of this operation produces an output size of (3, 5, 5) , clearly not summing

Wondering why scipy.spatial.distance.sqeuclidean is twice slower than numpy.sum((y1-y2)**2)

倖福魔咒の 提交于 2021-02-05 08:26:28
问题 Here is my code import numpy as np import time from scipy.spatial import distance y1=np.array([0,0,0,0,1,0,0,0,0,0]) y2=np.array([0. , 0.1, 0. , 0. , 0.7, 0.2, 0. , 0. , 0. , 0. ]) start_time = time.time() for i in range(1000000): distance.sqeuclidean(y1,y2) print("--- %s seconds ---" % (time.time() - start_time)) ---15.212640523910522 seconds--- start_time = time.time() for i in range(1000000): np.sum((y1-y2)**2) print("--- %s seconds ---" % (time.time() - start_time)) ---8.381187438964844--

Wondering why scipy.spatial.distance.sqeuclidean is twice slower than numpy.sum((y1-y2)**2)

扶醉桌前 提交于 2021-02-05 08:25:52
问题 Here is my code import numpy as np import time from scipy.spatial import distance y1=np.array([0,0,0,0,1,0,0,0,0,0]) y2=np.array([0. , 0.1, 0. , 0. , 0.7, 0.2, 0. , 0. , 0. , 0. ]) start_time = time.time() for i in range(1000000): distance.sqeuclidean(y1,y2) print("--- %s seconds ---" % (time.time() - start_time)) ---15.212640523910522 seconds--- start_time = time.time() for i in range(1000000): np.sum((y1-y2)**2) print("--- %s seconds ---" % (time.time() - start_time)) ---8.381187438964844--

Python: interpolate.UnivariateSpline package 'error: (m>k) failed for hidden m: fpcurf0:m=0'

好久不见. 提交于 2021-02-05 06:49:03
问题 I have been attempting to plot a line, along with a spline fitting. The following is a generalised version of my code. 'x_coord' and 'y_coord' are lists containing lists of float values. import matplotlib.pyplot as plt from scipy import interpolate as ipl for a in range(len(x_coord)): plt.plot(x_coord[a],y_coord[a],label='Label') yinterp = ipl.UnivariateSpline(x_coord[a],y_coord[a],s=1e4)(x_coord[a]) plt.plot(x_coord[a],yinterp,label='Spline Fit') While I believe this has worked for me in the

Python: interpolate.UnivariateSpline package 'error: (m>k) failed for hidden m: fpcurf0:m=0'

笑着哭i 提交于 2021-02-05 06:48:05
问题 I have been attempting to plot a line, along with a spline fitting. The following is a generalised version of my code. 'x_coord' and 'y_coord' are lists containing lists of float values. import matplotlib.pyplot as plt from scipy import interpolate as ipl for a in range(len(x_coord)): plt.plot(x_coord[a],y_coord[a],label='Label') yinterp = ipl.UnivariateSpline(x_coord[a],y_coord[a],s=1e4)(x_coord[a]) plt.plot(x_coord[a],yinterp,label='Spline Fit') While I believe this has worked for me in the

Solve complex matrix differential equation with Odeint

瘦欲@ 提交于 2021-02-04 21:13:47
问题 I want to solve a matrix differential equation, like this one: import numpy as np from scipy.integrate import odeint def deriv(A, t, Ab): return np.dot(Ab, A) Ab = np.array([[-0.25, 0, 0], [ 0.25, -0.2, 0], [ 0, 0.2, -0.1]]) time = np.linspace(0, 25, 101) A0 = np.array([10, 20, 30]) MA = odeint(deriv, A0, time, args=(Ab,)) However, this does not work in the case of having complex matrix elements. I am looking for something similar to scipy.integrate.complex_ode but for odeint . If this is not

Solve complex matrix differential equation with Odeint

♀尐吖头ヾ 提交于 2021-02-04 21:12:51
问题 I want to solve a matrix differential equation, like this one: import numpy as np from scipy.integrate import odeint def deriv(A, t, Ab): return np.dot(Ab, A) Ab = np.array([[-0.25, 0, 0], [ 0.25, -0.2, 0], [ 0, 0.2, -0.1]]) time = np.linspace(0, 25, 101) A0 = np.array([10, 20, 30]) MA = odeint(deriv, A0, time, args=(Ab,)) However, this does not work in the case of having complex matrix elements. I am looking for something similar to scipy.integrate.complex_ode but for odeint . If this is not

How to display a graph in ipython notebook

耗尽温柔 提交于 2021-02-04 17:51:07
问题 Trying to do some plotting in SymPy - As per this video I have written : from sympy.plotting import plot, plot_parametric e = sin(2*sin(x**3)) plot(e, (x, 0, 5)); But after evaling that cell I don't get any output? There isn't an error or anything, it just doesn't display anything. Another test : from sympy import * from sympy.plotting import plot, plot_parametric import math import numpy as np import pandas as pd import matplotlib.pyplot as plt expr = x**2 + sqrt(3)*x - Rational(1, 3) lf =

Finding the maximum of a curve scipy

我是研究僧i 提交于 2021-02-04 17:49:24
问题 I have fitted curve to a set of data points. I would like to know how to find the maximum point of my curve and then I would like to annotate that point (I don't want to use by largest y value from my data to do this). I cannot exactly write my code but here is the basic layout of my code. import matplotlib.pyplot as plt from scipy.optimize import curve_fit x = [1,2,3,4,5] y = [1,4,16,4,1] def f(x, p1, p2, p3): return p3*(p1/((x-p2)**2 + (p1/2)**2)) p0 = (8, 16, 0.1) # guess perameters plt

Finding the maximum of a curve scipy

最后都变了- 提交于 2021-02-04 17:48:13
问题 I have fitted curve to a set of data points. I would like to know how to find the maximum point of my curve and then I would like to annotate that point (I don't want to use by largest y value from my data to do this). I cannot exactly write my code but here is the basic layout of my code. import matplotlib.pyplot as plt from scipy.optimize import curve_fit x = [1,2,3,4,5] y = [1,4,16,4,1] def f(x, p1, p2, p3): return p3*(p1/((x-p2)**2 + (p1/2)**2)) p0 = (8, 16, 0.1) # guess perameters plt