当前位置: 首页>>代码示例>>Python>>正文


Python ndimage.mean方法代码示例

本文整理汇总了Python中scipy.ndimage.mean方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.mean方法的具体用法?Python ndimage.mean怎么用?Python ndimage.mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.mean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: labelmeanfilter_nd

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def labelmeanfilter_nd(y, x):
   # requires integer labels
   # from mailing list scipy-user 2009-02-11
   # adjusted for 2d x with column variables

   labelsunique = np.arange(np.max(y)+1)
   labmeansdata = []
   labmeans = []

   for xx in x.T:
      labelmeans = np.array(ndimage.mean(xx, labels=y, index=labelsunique))
      labmeansdata.append(labelmeans[y])
      labmeans.append(labelmeans)
   # group count:
   labelcount = np.array(ndimage.histogram(y, labelsunique[0], labelsunique[-1]+1,
                        1, labels=y, index=labelsunique))

   # returns array of lable/group counts and of label/group means
   #         and label/group means for each original observation
   return labelcount, np.array(labmeans), np.array(labmeansdata).T 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:try_catdata.py

示例2: test_stat_funcs_2d

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_stat_funcs_2d():
    """Apply the stat funcs to a 2-d array."""
    a = np.array([[5,6,0,0,0], [8,9,0,0,0], [0,0,0,3,5]])
    lbl = np.array([[1,1,0,0,0], [1,1,0,0,0], [0,0,0,2,2]])

    mean = ndimage.mean(a, labels=lbl, index=[1, 2])
    assert_array_equal(mean, [7.0, 4.0])

    var = ndimage.variance(a, labels=lbl, index=[1, 2])
    assert_array_equal(var, [2.5, 1.0])

    std = ndimage.standard_deviation(a, labels=lbl, index=[1, 2])
    assert_array_almost_equal(std, np.sqrt([2.5, 1.0]))

    med = ndimage.median(a, labels=lbl, index=[1, 2])
    assert_array_equal(med, [7.0, 4.0])

    min = ndimage.minimum(a, labels=lbl, index=[1, 2])
    assert_array_equal(min, [5, 3])

    max = ndimage.maximum(a, labels=lbl, index=[1, 2])
    assert_array_equal(max, [9, 5]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_measurements.py

示例3: apply

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def apply(self):
        sc = self.scene
        org = self.original
        factor = self.factor

        sx, sy = sc.displacement.shape
        gx, gy = num.ogrid[0:sx, 0:sy]
        regions = sy/factor * (gx/factor) + gy/factor
        indices = num.arange(regions.max() + 1)

        def block_downsample(arr):
            res = ndimage.mean(
                arr,
                labels=regions,
                index=indices)
            res.shape = (sx/factor, sy/factor)
            return res

        sc.displacement = block_downsample(sc.displacement)
        sc.theta = block_downsample(sc.theta)
        sc.phi = block_downsample(sc.phi)
        sc.frame.dLat = org['frame.dLat'] * self.factor
        sc.frame.dLon = org['frame.dLat'] * self.factor 
开发者ID:pyrocko,项目名称:kite,代码行数:25,代码来源:scene_processing.py

示例4: test_stat_funcs_2d

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_stat_funcs_2d():
    a = np.array([[5,6,0,0,0], [8,9,0,0,0], [0,0,0,3,5]])
    lbl = np.array([[1,1,0,0,0], [1,1,0,0,0], [0,0,0,2,2]])

    mean = ndimage.mean(a, labels=lbl, index=[1, 2])
    assert_array_equal(mean, [7.0, 4.0])

    var = ndimage.variance(a, labels=lbl, index=[1, 2])
    assert_array_equal(var, [2.5, 1.0])

    std = ndimage.standard_deviation(a, labels=lbl, index=[1, 2])
    assert_array_almost_equal(std, np.sqrt([2.5, 1.0]))

    med = ndimage.median(a, labels=lbl, index=[1, 2])
    assert_array_equal(med, [7.0, 4.0])

    min = ndimage.minimum(a, labels=lbl, index=[1, 2])
    assert_array_equal(min, [5, 3])

    max = ndimage.maximum(a, labels=lbl, index=[1, 2])
    assert_array_equal(max, [9, 5]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:test_measurements.py

示例5: labelmeanfilter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def labelmeanfilter(y, x):
   # requires integer labels
   # from mailing list scipy-user 2009-02-11
   labelsunique = np.arange(np.max(y)+1)
   labelmeans = np.array(ndimage.mean(x, labels=y, index=labelsunique))
   # returns label means for each original observation
   return labelmeans[y]

#groupcount: i.e. number of observation by group/label
#np.array(ndimage.histogram(yrvs[:,0],0,10,1,labels=yrvs[:,0],index=np.unique(yrvs[:,0]))) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:try_catdata.py

示例6: labelmeanfilter_str

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def labelmeanfilter_str(ys, x):
    # works also for string labels in ys, but requires 1D
    # from mailing list scipy-user 2009-02-11
    unil, unilinv = np.unique(ys, return_index=False, return_inverse=True)
    labelmeans = np.array(ndimage.mean(x, labels=unilinv, index=np.arange(np.max(unil)+1)))
    arr3 = labelmeans[unilinv]
    return arr3 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:try_catdata.py

示例7: groupsstats_1d

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def groupsstats_1d(y, x, labelsunique):
    '''use ndimage to get fast mean and variance'''
    labelmeans = np.array(ndimage.mean(x, labels=y, index=labelsunique))
    labelvars = np.array(ndimage.var(x, labels=y, index=labelsunique))
    return labelmeans, labelvars 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:try_catdata.py

示例8: groupsstats_dummy

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def groupsstats_dummy(y, x, nonseq=0):
    if x.ndim == 1:
        # use groupsstats_1d
        x = x[:,np.newaxis]
    dummy = cat2dummy(y, nonseq=nonseq)
    countgr = dummy.sum(0, dtype=float)
    meangr = np.dot(x.T,dummy)/countgr
    meandata = np.dot(dummy,meangr.T) # category/group means as array in shape of x
    xdevmeangr = x - meandata  # deviation from category/group mean
    vargr = np.dot((xdevmeangr * xdevmeangr).T, dummy) / countgr
    return meangr, vargr, xdevmeangr, countgr 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:try_catdata.py

示例9: test_mean01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean01():
    "mean 1"
    labels = np.array([1, 0], bool)
    for type in types:
        input = np.array([[1, 2], [3, 4]], type)
        output = ndimage.mean(input, labels=labels)
        assert_almost_equal(output, 2.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_measurements.py

示例10: test_mean02

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean02():
    "mean 2"
    labels = np.array([1, 0], bool)
    input = np.array([[1, 2], [3, 4]], bool)
    output = ndimage.mean(input, labels=labels)
    assert_almost_equal(output, 1.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:test_measurements.py

示例11: test_mean03

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean03():
    "mean 3"
    labels = np.array([1, 2])
    for type in types:
        input = np.array([[1, 2], [3, 4]], type)
        output = ndimage.mean(input, labels=labels,
                                        index=2)
        assert_almost_equal(output, 3.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_measurements.py

示例12: test_mean04

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean04():
    "mean 4"
    labels = np.array([[1, 2], [2, 4]], np.int8)
    olderr = np.seterr(all='ignore')
    try:
        for type in types:
            input = np.array([[1, 2], [3, 4]], type)
            output = ndimage.mean(input, labels=labels,
                                            index=[4, 8, 2])
            assert_array_almost_equal(output[[0,2]], [4.0, 2.5])
            assert_(np.isnan(output[1]))
    finally:
        np.seterr(**olderr) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:test_measurements.py

示例13: test_mean01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean01():
    labels = np.array([1, 0], bool)
    for type in types:
        input = np.array([[1, 2], [3, 4]], type)
        output = ndimage.mean(input, labels=labels)
        assert_almost_equal(output, 2.0) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:test_measurements.py

示例14: test_mean02

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean02():
    labels = np.array([1, 0], bool)
    input = np.array([[1, 2], [3, 4]], bool)
    output = ndimage.mean(input, labels=labels)
    assert_almost_equal(output, 1.0) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_measurements.py

示例15: test_mean03

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean03():
    labels = np.array([1, 2])
    for type in types:
        input = np.array([[1, 2], [3, 4]], type)
        output = ndimage.mean(input, labels=labels,
                                        index=2)
        assert_almost_equal(output, 3.0) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_measurements.py


注:本文中的scipy.ndimage.mean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。