當前位置: 首頁>>代碼示例>>Python>>正文


Python ndimage.histogram方法代碼示例

本文整理匯總了Python中scipy.ndimage.histogram方法的典型用法代碼示例。如果您正苦於以下問題:Python ndimage.histogram方法的具體用法?Python ndimage.histogram怎麽用?Python ndimage.histogram使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.histogram方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: labelmeanfilter_nd

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [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: entropy2

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def entropy2(x, y):
    '''Joint entropy of paired samples X and Y'''
    #
    # Bin each image into 256 gray levels
    #
    x = (stretch(x) * 255).astype(int)
    y = (stretch(y) * 255).astype(int)
    #
    # create an image where each pixel with the same X & Y gets
    # the same value
    #
    xy = 256 * x + y
    xy = xy.flatten()
    sparse = scipy.sparse.coo_matrix((np.ones(xy.shape),
                                      (xy, np.zeros(xy.shape))))
    histogram = sparse.toarray()
    n = np.sum(histogram)
    if n > 0 and np.max(histogram) > 0:
        histogram = histogram[histogram > 0]
        return np.log2(n) - old_div(np.sum(histogram * np.log2(histogram)), n)
    else:
        return 0 
開發者ID:losonczylab,項目名稱:sima,代碼行數:24,代碼來源:align.py

示例3: labelmeanfilter

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [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

示例4: test_histogram01

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram01():
    "histogram 1"
    expected = np.ones(10)
    input = np.arange(10)
    output = ndimage.histogram(input, 0, 10, 10)
    assert_array_almost_equal(output, expected) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_measurements.py

示例5: test_histogram02

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram02():
    "histogram 2"
    labels = [1, 1, 1, 1, 2, 2, 2, 2]
    expected = [0, 2, 0, 1, 1]
    input = np.array([1, 1, 3, 4, 3, 3, 3, 3])
    output = ndimage.histogram(input, 0, 4, 5, labels, 1)
    assert_array_almost_equal(output, expected) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:9,代碼來源:test_measurements.py

示例6: test_histogram03

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram03():
    "histogram 3"
    labels = [1, 0, 1, 1, 2, 2, 2, 2]
    expected1 = [0, 1, 0, 1, 1]
    expected2 = [0, 0, 0, 3, 0]
    input = np.array([1, 1, 3, 4, 3, 5, 3, 3])
    output = ndimage.histogram(input, 0, 4, 5, labels, (1,2))

    assert_array_almost_equal(output[0], expected1)
    assert_array_almost_equal(output[1], expected2) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_measurements.py

示例7: test_histogram01

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram01():
    expected = np.ones(10)
    input = np.arange(10)
    output = ndimage.histogram(input, 0, 10, 10)
    assert_array_almost_equal(output, expected) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_measurements.py

示例8: test_histogram02

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram02():
    labels = [1, 1, 1, 1, 2, 2, 2, 2]
    expected = [0, 2, 0, 1, 1]
    input = np.array([1, 1, 3, 4, 3, 3, 3, 3])
    output = ndimage.histogram(input, 0, 4, 5, labels, 1)
    assert_array_almost_equal(output, expected) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:8,代碼來源:test_measurements.py

示例9: test_histogram03

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram03():
    labels = [1, 0, 1, 1, 2, 2, 2, 2]
    expected1 = [0, 1, 0, 1, 1]
    expected2 = [0, 0, 0, 3, 0]
    input = np.array([1, 1, 3, 4, 3, 5, 3, 3])
    output = ndimage.histogram(input, 0, 4, 5, labels, (1,2))

    assert_array_almost_equal(output[0], expected1)
    assert_array_almost_equal(output[1], expected2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:test_measurements.py

示例10: test_histogram

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def test_histogram(shape, chunks, has_lbls, ind, min, max, bins):
    a = np.random.random(shape)
    d = da.from_array(a, chunks=chunks)

    lbls = None
    d_lbls = None

    if has_lbls:
        lbls = np.zeros(a.shape, dtype=np.int64)
        lbls += (
            (a < 0.5).astype(lbls.dtype) +
            (a < 0.25).astype(lbls.dtype) +
            (a < 0.125).astype(lbls.dtype) +
            (a < 0.0625).astype(lbls.dtype)
        )
        d_lbls = da.from_array(lbls, chunks=d.chunks)

    a_r = spnd.histogram(a, min, max, bins, lbls, ind)
    d_r = dask_image.ndmeasure.histogram(d, min, max, bins, d_lbls, ind)

    if ind is None or np.isscalar(ind):
        if a_r is None:
            assert d_r.compute() is None
        else:
            np.allclose(a_r, d_r.compute(), equal_nan=True)
    else:
        assert a_r.dtype == d_r.dtype
        assert a_r.shape == d_r.shape
        for i in it.product(*[range(_) for _ in a_r.shape]):
            if a_r[i] is None:
                assert d_r[i].compute() is None
            else:
                assert np.allclose(a_r[i], d_r[i].compute(), equal_nan=True) 
開發者ID:dask,項目名稱:dask-image,代碼行數:35,代碼來源:test_core.py

示例11: entropy

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import histogram [as 別名]
def entropy(x):
    '''The entropy of x as if x is a probability distribution'''
    histogram = scind.histogram(x.astype(float), np.min(x), np.max(x), 256)
    n = np.sum(histogram)
    if n > 0 and np.max(histogram) > 0:
        histogram = histogram[histogram != 0]
        return np.log2(n) - old_div(np.sum(histogram * np.log2(histogram)), n)
    else:
        return 0 
開發者ID:losonczylab,項目名稱:sima,代碼行數:11,代碼來源:align.py


注:本文中的scipy.ndimage.histogram方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。