當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。