• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python histograms.histogramdd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.lib.histograms.histogramdd函数的典型用法代码示例。如果您正苦于以下问题:Python histogramdd函数的具体用法?Python histogramdd怎么用?Python histogramdd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_finite_range

 def test_finite_range(self):
     vals = np.random.random((100, 3))
     histogramdd(vals, range=[[0.0, 1.0], [0.25, 0.75], [0.25, 0.5]])
     assert_raises(ValueError, histogramdd, vals,
                   range=[[0.0, 1.0], [0.25, 0.75], [0.25, np.inf]])
     assert_raises(ValueError, histogramdd, vals,
                   range=[[0.0, 1.0], [np.nan, 0.75], [0.25, 0.5]])
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:7,代码来源:test_histograms.py


示例2: test_density_non_uniform_2d

    def test_density_non_uniform_2d(self):
        # Defines the following grid:
        #
        #    0 2     8
        #   0+-+-----+
        #    + |     +
        #    + |     +
        #   6+-+-----+
        #   8+-+-----+
        x_edges = np.array([0, 2, 8])
        y_edges = np.array([0, 6, 8])
        relative_areas = np.array([
            [3, 9],
            [1, 3]])

        # ensure the number of points in each region is proportional to its area
        x = np.array([1] + [1]*3 + [7]*3 + [7]*9)
        y = np.array([7] + [1]*3 + [7]*3 + [1]*9)

        # sanity check that the above worked as intended
        hist, edges = histogramdd((y, x), bins=(y_edges, x_edges))
        assert_equal(hist, relative_areas)

        # resulting histogram should be uniform, since counts and areas are propotional
        hist, edges = histogramdd((y, x), bins=(y_edges, x_edges), density=True)
        assert_equal(hist, 1 / (8*8))
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:26,代码来源:test_histograms.py


示例3: test_weights

 def test_weights(self):
     v = np.random.rand(100, 2)
     hist, edges = histogramdd(v)
     n_hist, edges = histogramdd(v, density=True)
     w_hist, edges = histogramdd(v, weights=np.ones(100))
     assert_array_equal(w_hist, hist)
     w_hist, edges = histogramdd(v, weights=np.ones(100) * 2, density=True)
     assert_array_equal(w_hist, n_hist)
     w_hist, edges = histogramdd(v, weights=np.ones(100, int) * 2)
     assert_array_equal(w_hist, 2 * hist)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:10,代码来源:test_histograms.py


示例4: test_density_normed_redundancy

 def test_density_normed_redundancy(self):
     v = np.arange(10)
     bins = np.array([0, 1, 3, 6, 10])
     with assert_raises_regex(TypeError, "Cannot specify both"):
         hist_dd, edges_dd = histogramdd((v,), (bins,),
                                         density=True,
                                         normed=True)
开发者ID:Horta,项目名称:numpy,代码行数:7,代码来源:test_histograms.py


示例5: test_density_non_uniform_1d

 def test_density_non_uniform_1d(self):
     # compare to histogram to show the results are the same
     v = np.arange(10)
     bins = np.array([0, 1, 3, 6, 10])
     hist, edges = histogram(v, bins, density=True)
     hist_dd, edges_dd = histogramdd((v,), (bins,), density=True)
     assert_equal(hist, hist_dd)
     assert_equal(edges, edges_dd[0])
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:8,代码来源:test_histograms.py


示例6: test_shape_3d

 def test_shape_3d(self):
     # All possible permutations for bins of different lengths in 3D.
     bins = ((5, 4, 6), (6, 4, 5), (5, 6, 4), (4, 6, 5), (6, 5, 4),
             (4, 5, 6))
     r = np.random.rand(10, 3)
     for b in bins:
         H, edges = histogramdd(r, b)
         assert_(H.shape == b)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:8,代码来源:test_histograms.py


示例7: test_density_via_normed

 def test_density_via_normed(self):
     # normed should simply alias to density argument
     v = np.arange(10)
     bins = np.array([0, 1, 3, 6, 10])
     hist, edges = histogram(v, bins, density=True)
     hist_dd, edges_dd = histogramdd((v,), (bins,), normed=True)
     assert_equal(hist, hist_dd)
     assert_equal(edges, edges_dd[0])
开发者ID:Horta,项目名称:numpy,代码行数:8,代码来源:test_histograms.py


示例8: test_edge_dtype

    def test_edge_dtype(self):
        """ Test that if an edge array is input, its type is preserved """
        x = np.array([0, 10, 20])
        y = x / 10
        x_edges = np.array([0, 5, 15, 20])
        y_edges = x_edges / 10
        hist, edges = histogramdd((x, y), bins=(x_edges, y_edges))

        assert_equal(edges[0].dtype, x_edges.dtype)
        assert_equal(edges[1].dtype, y_edges.dtype)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:10,代码来源:test_histograms.py


示例9: test_large_integers

    def test_large_integers(self):
        big = 2**60  # Too large to represent with a full precision float

        x = np.array([0], np.int64)
        x_edges = np.array([-1, +1], np.int64)
        y = big + x
        y_edges = big + x_edges

        hist, edges = histogramdd((x, y), bins=(x_edges, y_edges))

        assert_equal(hist[0, 0], 1)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:11,代码来源:test_histograms.py


示例10: test_equal_edges

    def test_equal_edges(self):
        """ Test that adjacent entries in an edge array can be equal """
        x = np.array([0, 1, 2])
        y = np.array([0, 1, 2])
        x_edges = np.array([0, 2, 2])
        y_edges = 1
        hist, edges = histogramdd((x, y), bins=(x_edges, y_edges))

        hist_expected = np.array([
            [2.],
            [1.],  # x == 2 falls in the final bin
        ])
        assert_equal(hist, hist_expected)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:13,代码来源:test_histograms.py


示例11: test_rightmost_binedge

 def test_rightmost_binedge(self):
     # Test event very close to rightmost binedge. See Github issue #4266
     x = [0.9999999995]
     bins = [[0., 0.5, 1.0]]
     hist, _ = histogramdd(x, bins=bins)
     assert_(hist[0] == 0.0)
     assert_(hist[1] == 1.)
     x = [1.0]
     bins = [[0., 0.5, 1.0]]
     hist, _ = histogramdd(x, bins=bins)
     assert_(hist[0] == 0.0)
     assert_(hist[1] == 1.)
     x = [1.0000000001]
     bins = [[0., 0.5, 1.0]]
     hist, _ = histogramdd(x, bins=bins)
     assert_(hist[0] == 0.0)
     assert_(hist[1] == 0.0)
     x = [1.0001]
     bins = [[0., 0.5, 1.0]]
     hist, _ = histogramdd(x, bins=bins)
     assert_(hist[0] == 0.0)
     assert_(hist[1] == 0.0)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:22,代码来源:test_histograms.py


示例12: test_simple

    def test_simple(self):
        x = np.array([[-.5, .5, 1.5], [-.5, 1.5, 2.5], [-.5, 2.5, .5],
                      [.5,  .5, 1.5], [.5,  1.5, 2.5], [.5,  2.5, 2.5]])
        H, edges = histogramdd(x, (2, 3, 3),
                               range=[[-1, 1], [0, 3], [0, 3]])
        answer = np.array([[[0, 1, 0], [0, 0, 1], [1, 0, 0]],
                           [[0, 1, 0], [0, 0, 1], [0, 0, 1]]])
        assert_array_equal(H, answer)

        # Check normalization
        ed = [[-2, 0, 2], [0, 1, 2, 3], [0, 1, 2, 3]]
        H, edges = histogramdd(x, bins=ed, density=True)
        assert_(np.all(H == answer / 12.))

        # Check that H has the correct shape.
        H, edges = histogramdd(x, (2, 3, 4),
                               range=[[-1, 1], [0, 3], [0, 4]],
                               density=True)
        answer = np.array([[[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0]],
                           [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]]])
        assert_array_almost_equal(H, answer / 6., 4)
        # Check that a sequence of arrays is accepted and H has the correct
        # shape.
        z = [np.squeeze(y) for y in np.split(x, 3, axis=1)]
        H, edges = histogramdd(
            z, bins=(4, 3, 2), range=[[-2, 2], [0, 3], [0, 2]])
        answer = np.array([[[0, 0], [0, 0], [0, 0]],
                           [[0, 1], [0, 0], [1, 0]],
                           [[0, 1], [0, 0], [0, 0]],
                           [[0, 0], [0, 0], [0, 0]]])
        assert_array_equal(H, answer)

        Z = np.zeros((5, 5, 5))
        Z[list(range(5)), list(range(5)), list(range(5))] = 1.
        H, edges = histogramdd([np.arange(5), np.arange(5), np.arange(5)], 5)
        assert_array_equal(H, Z)
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:36,代码来源:test_histograms.py


示例13: test_empty

 def test_empty(self):
     a, b = histogramdd([[], []], bins=([0, 1], [0, 1]))
     assert_array_max_ulp(a, np.array([[0.]]))
     a, b = np.histogramdd([[], [], []], bins=2)
     assert_array_max_ulp(a, np.zeros((2, 2, 2)))
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:5,代码来源:test_histograms.py


示例14: test_identical_samples

 def test_identical_samples(self):
     x = np.zeros((10, 2), int)
     hist, edges = histogramdd(x, bins=2)
     assert_array_equal(edges[0], np.array([-0.5, 0., 0.5]))
开发者ID:dpritsos,项目名称:DoGSWrapper,代码行数:4,代码来源:test_histograms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python recfunctions.append_fields函数代码示例发布时间:2022-05-27
下一篇:
Python histograms.histogram函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap