scipy fftconvolve声称输入参数的维数不相同。我要解析什么?

尼古拉·Z

我试图创建一个使用一个类fftconvolvescipy.signal与类实例的方法中高斯进行卷积一些数据。但是,每次创建实例并调用方法expand_smooth(在按右箭头键时发生)时,我从fftconvolve收到一条错误消息,指出:ValueError:in1和in2应该具有相同的维数def fftconvolve(in1, in2, mode="full"):当该行的elif not in1.ndim == in2.ndim:值为True时,这就会在函数中发生不过我行print vals.ndim == gs.ndim打印真正调用之前fftconvolve,都丘壑GS的尺寸是(101)所以,如果我不解析瓦尔斯GSfftconvolve我是什么分析?为什么不起作用?

class Smoother(object):
    import sys
    sys.path.append("/DATA/Pythonfunktioner")
    from scipy.signal import fftconvolve
    import pyximport; pyximport.install()
    from fitting6 import gs_smooth1
    """
    This class allows the user to smooth any function of one variable with a gaussian using fftconvolve while looking at the smoothed function. The smoothing parameter is changed with the arrow keys and finally chosen with enter.
    """

    def __init__(self, data):
        self.data = data
        self.sigma = 1 #smallest possible sigma for this smoothing
        self.arr = np.arange(len(self.data.get_ydata()), dtype='float64') - len(self.data.get_ydata())/2
        self.stack = [data]
        self.line = data
        self.active = True

    def connect(self):
        self.cidkpress = self.data.figure.canvas.mpl_connect('key_press_event', self.key)

    def key(self, event):
        if event.key == 'right':
            self.enlarge_smooth()
        elif event.key == 'left':
            self.lower_smooth()
        elif event.key == 'enter':
            self.term(event)

    def enlarge_smooth(self):
        if 0: #Check if larger smooth is already in stack
            pass#set larger smooth as current
        else:
            gs = self.gs_smooth1(self.arr.copy(), self.sigma) #Gaussian core centered at 0
            vals = self.data.get_ydata().copy()
            print vals.ndim == gs.ndim
            print vals.ndim, type(vals), vals.dtype
            print gs.ndim, type(gs), gs.dtype
#            print vals, type(vals), vals.dtype
#            print gs, type(gs), gs.dtype
            newsmooth = self.fftconvolve(vals, gs)
            self.line = Line2D(self.data.get_xdata(), newsmooth)
            self.stack.append(self.line)

    def lower_smooth(self):
        if 1: #Check if current smooth is lowest possible
            print "Cannot smooth less. Least smooth already active."
        else:
            pass#Set lesser smooth as current

    def term(self, event):
        self.active = False
        self.disconnect()

    def disconnect(self):
        self.data.figure.canvas.mpl_disconnect(self.cidkpress)

我还尝试了解析vals[0]gs[0]然后检查是否要解析两个长度为101的列表。事实证明,我实际上只是解析了两个标量,而ftconvolve会退出并显示错误:TypeError:不支持的操作数类型*:“平滑”和“浮动”

好像我正在解析该类本身的实例。我只是不知道如何。

如果它有助于通过即时通讯测试我的班级对以下函数的调用

def smoothBF(datalist):
    from matplotlib import pyplot as plt
    for i in xrange(len(datalist)):
        fig, axs = plt.subplots(nrows=1, ncols=1)
        data, = axs.plot(datalist[i][0], datalist[i][1])
        smoother = Smoother(data)
        smoother.connect()
        while smoother.active:
            plt.pause(0.1)
        #Return current result
        plt.close(fig)

其中datalist是仅包含元组的列表(np.arange(101), np.random.random(101))

更新:这似乎与在类定义中导入fftconvolve有关。添加一些打印语句以获取scipy fftconvolve函数内部的尺寸类型和数量,这表明in1某种程度上是一种更平滑的类型。但是,当我from scipy.signal import fftconvolve在模块顶部newsmooth = fftconvolve(vals, gs)而不是在类定义内部调用而不是时,它也会产生不同的结果newsmooth = self.fftconvolve(vals, gs)然后我收到错误消息AttributeError:'numpy.ndarray'对象没有来自fftconvolve的属性'ndims'

用户名

您要fftconvolve在类定义中导入的“技巧”最终会使您感到困惑。除非您没有向我们展示您Smooth.fftconvolve在其他地方定义的位置

这是您现在拥有的:

class Smooth(object):
    from scipy.signal import fftconvolve

    def enlarge_smooth(self):
        # other stuff
        self.fftconvolve(vals, gs)

当你打电话时

s = S()
s.enlarge_smooth()

fftconvolve 将被称为

fftconvolve(self, vals, gs)

解决方案很简单:不要做这种骗术。相反,请导入fftconvolve类外部,然后直接调用该函数:

from scipy.signal import fftconvolve

class Smooth(object):

    def enlarge_smooth(self):
        # other stuff
        fftconvolve(vals, gs)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

scipy.optimize.minimize:ValueError:所有输入数组的维数必须相同

来自分类Dev

为什么从scipy导入空间工作,而scipy.spatial在导入scipy之后不起作用?

来自分类Dev

SciPy:稀疏数据的n维插值

来自分类Dev

具有多个输入的Scipy LinearOperator

来自分类Dev

在SciPy中使用固定参数拟合分布

来自分类Dev

多参数函数的scipy.misc.derivative

来自分类Dev

Python + scipy中的S形回归参数

来自分类Dev

Scipy.optimize:如何限制参数值

来自分类Dev

如何使用scipy minimum()传递固定参数?

来自分类Dev

用scipy拟合多条参数曲线

来自分类Dev

Scipy odeint不带参数或括号的方法

来自分类Dev

Python + scipy中的S形回归参数

来自分类Dev

我很难理解scipy.optimize的语法

来自分类Dev

我的scipy.misc模块似乎丢失了

来自分类Dev

SciPy。我如何求解微分方程?

来自分类Dev

在scipy的ConvexHull中,“区域”测量什么?

来自分类Dev

为什么Scipy stdDev返回错误的结果?

来自分类Dev

为什么Scipy的KDTree这么慢?

来自分类Dev

scipy.linalg.lu返回什么?

来自分类Dev

为什么Scipy stdDev返回错误的结果?

来自分类Dev

多元优化-scipy.optimize输入解析错误

来自分类Dev

scipy.spatial.distance.euclidean 和 scipy.spatial.- distance_matrix 不返回相同的结果

来自分类Dev

scipy.stats.zipf 中的参数是什么意思?

来自分类Dev

没有名为scipy.stats的模块-为什么尽管已安装scipy

来自分类Dev

scipy.special.binom和scipy.misc.comb有什么区别?

来自分类Dev

scipy.integrate.odeint和scipy.integrate.ode有什么区别?

来自分类Dev

为什么不使用Scipy的FFT代码结果与Scipy FFT不一样?

来自分类Dev

scipy.interpolate.splrep和scipy.interpolate.UnivariateSpline之间的用例有什么区别?

来自分类Dev

scipy.integrate.odeint和scipy.integrate.ode有什么区别?

Related 相关文章

  1. 1

    scipy.optimize.minimize:ValueError:所有输入数组的维数必须相同

  2. 2

    为什么从scipy导入空间工作,而scipy.spatial在导入scipy之后不起作用?

  3. 3

    SciPy:稀疏数据的n维插值

  4. 4

    具有多个输入的Scipy LinearOperator

  5. 5

    在SciPy中使用固定参数拟合分布

  6. 6

    多参数函数的scipy.misc.derivative

  7. 7

    Python + scipy中的S形回归参数

  8. 8

    Scipy.optimize:如何限制参数值

  9. 9

    如何使用scipy minimum()传递固定参数?

  10. 10

    用scipy拟合多条参数曲线

  11. 11

    Scipy odeint不带参数或括号的方法

  12. 12

    Python + scipy中的S形回归参数

  13. 13

    我很难理解scipy.optimize的语法

  14. 14

    我的scipy.misc模块似乎丢失了

  15. 15

    SciPy。我如何求解微分方程?

  16. 16

    在scipy的ConvexHull中,“区域”测量什么?

  17. 17

    为什么Scipy stdDev返回错误的结果?

  18. 18

    为什么Scipy的KDTree这么慢?

  19. 19

    scipy.linalg.lu返回什么?

  20. 20

    为什么Scipy stdDev返回错误的结果?

  21. 21

    多元优化-scipy.optimize输入解析错误

  22. 22

    scipy.spatial.distance.euclidean 和 scipy.spatial.- distance_matrix 不返回相同的结果

  23. 23

    scipy.stats.zipf 中的参数是什么意思?

  24. 24

    没有名为scipy.stats的模块-为什么尽管已安装scipy

  25. 25

    scipy.special.binom和scipy.misc.comb有什么区别?

  26. 26

    scipy.integrate.odeint和scipy.integrate.ode有什么区别?

  27. 27

    为什么不使用Scipy的FFT代码结果与Scipy FFT不一样?

  28. 28

    scipy.interpolate.splrep和scipy.interpolate.UnivariateSpline之间的用例有什么区别?

  29. 29

    scipy.integrate.odeint和scipy.integrate.ode有什么区别?

热门标签

归档