当前位置: 首页>>代码示例>>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;未经允许,请勿转载。