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

Python core.block函数代码示例

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

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



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

示例1: test_nested

    def test_nested(self, block):
        one = np.array([1, 1, 1])
        two = np.array([[2, 2, 2], [2, 2, 2], [2, 2, 2]])
        three = np.array([3, 3, 3])
        four = np.array([4, 4, 4])
        five = np.array(5)
        six = np.array([6, 6, 6, 6, 6])
        zero = np.zeros((2, 6))

        result = block([
            [
                block([
                   [one],
                   [three],
                   [four]
                ]),
                two
            ],
            [five, six],
            [zero]
        ])
        expected = np.array([[1, 1, 1, 2, 2, 2],
                             [3, 3, 3, 2, 2, 2],
                             [4, 4, 4, 2, 2, 2],
                             [5, 6, 6, 6, 6, 6],
                             [0, 0, 0, 0, 0, 0],
                             [0, 0, 0, 0, 0, 0]])

        assert_equal(result, expected)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:29,代码来源:test_shape_base.py


示例2: test_block_memory_order

    def test_block_memory_order(self, block):
        # 3D
        arr_c = np.zeros((3,)*3, order='C')
        arr_f = np.zeros((3,)*3, order='F')

        b_c = [[[arr_c, arr_c],
                [arr_c, arr_c]],
               [[arr_c, arr_c],
                [arr_c, arr_c]]]

        b_f = [[[arr_f, arr_f],
                [arr_f, arr_f]],
               [[arr_f, arr_f],
                [arr_f, arr_f]]]

        assert block(b_c).flags['C_CONTIGUOUS']
        assert block(b_f).flags['F_CONTIGUOUS']

        arr_c = np.zeros((3, 3), order='C')
        arr_f = np.zeros((3, 3), order='F')
        # 2D
        b_c = [[arr_c, arr_c],
               [arr_c, arr_c]]

        b_f = [[arr_f, arr_f],
               [arr_f, arr_f]]

        assert block(b_c).flags['C_CONTIGUOUS']
        assert block(b_f).flags['F_CONTIGUOUS']
开发者ID:ales-erjavec,项目名称:numpy,代码行数:29,代码来源:test_shape_base.py


示例3: test_block_with_1d_arrays_multiple_rows

 def test_block_with_1d_arrays_multiple_rows(self, block):
     a = np.array([1, 2, 3])
     b = np.array([2, 3, 4])
     expected = np.array([[1, 2, 3, 2, 3, 4],
                          [1, 2, 3, 2, 3, 4]])
     result = block([[a, b], [a, b]])
     assert_equal(expected, result)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例4: test_block_with_1d_arrays_row_wise

 def test_block_with_1d_arrays_row_wise(self, block):
     # # # 1-D vectors are treated as row arrays
     a = np.array([1, 2, 3])
     b = np.array([2, 3, 4])
     expected = np.array([1, 2, 3, 2, 3, 4])
     result = block([a, b])
     assert_equal(expected, result)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例5: test_block_simple_row_wise

 def test_block_simple_row_wise(self, block):
     a_2d = np.ones((2, 2))
     b_2d = 2 * a_2d
     desired = np.array([[1, 1, 2, 2],
                         [1, 1, 2, 2]])
     result = block([a_2d, b_2d])
     assert_equal(desired, result)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例6: test_block_mixed_1d_and_2d

 def test_block_mixed_1d_and_2d(self, block):
     a_2d = np.ones((2, 2))
     b_1d = np.array([2, 2])
     result = block([[a_2d], [b_1d]])
     expected = np.array([[1, 1],
                          [1, 1],
                          [2, 2]])
     assert_equal(expected, result)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:8,代码来源:test_shape_base.py


示例7: test_block_with_1d_arrays_column_wise

 def test_block_with_1d_arrays_column_wise(self, block):
     # # # 1-D vectors are treated as row arrays
     a_1d = np.array([1, 2, 3])
     b_1d = np.array([2, 3, 4])
     expected = np.array([[1, 2, 3],
                          [2, 3, 4]])
     result = block([[a_1d], [b_1d]])
     assert_equal(expected, result)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:8,代码来源:test_shape_base.py


示例8: test_different_ndims

    def test_different_ndims(self, block):
        a = 1.
        b = 2 * np.ones((1, 2))
        c = 3 * np.ones((1, 1, 3))

        result = block([a, b, c])
        expected = np.array([[[1., 2., 2., 3., 3., 3.]]])

        assert_equal(result, expected)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:9,代码来源:test_shape_base.py


示例9: test_block_simple_column_wise

 def test_block_simple_column_wise(self, block):
     a_2d = np.ones((2, 2))
     b_2d = 2 * a_2d
     expected = np.array([[1, 1],
                          [1, 1],
                          [2, 2],
                          [2, 2]])
     result = block([[a_2d], [b_2d]])
     assert_equal(expected, result)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:9,代码来源:test_shape_base.py


示例10: test_3d

    def test_3d(self, block):
        a000 = np.ones((2, 2, 2), int) * 1

        a100 = np.ones((3, 2, 2), int) * 2
        a010 = np.ones((2, 3, 2), int) * 3
        a001 = np.ones((2, 2, 3), int) * 4

        a011 = np.ones((2, 3, 3), int) * 5
        a101 = np.ones((3, 2, 3), int) * 6
        a110 = np.ones((3, 3, 2), int) * 7

        a111 = np.ones((3, 3, 3), int) * 8

        result = block([
            [
                [a000, a001],
                [a010, a011],
            ],
            [
                [a100, a101],
                [a110, a111],
            ]
        ])
        expected = array([[[1, 1, 4, 4, 4],
                           [1, 1, 4, 4, 4],
                           [3, 3, 5, 5, 5],
                           [3, 3, 5, 5, 5],
                           [3, 3, 5, 5, 5]],

                          [[1, 1, 4, 4, 4],
                           [1, 1, 4, 4, 4],
                           [3, 3, 5, 5, 5],
                           [3, 3, 5, 5, 5],
                           [3, 3, 5, 5, 5]],

                          [[2, 2, 6, 6, 6],
                           [2, 2, 6, 6, 6],
                           [7, 7, 8, 8, 8],
                           [7, 7, 8, 8, 8],
                           [7, 7, 8, 8, 8]],

                          [[2, 2, 6, 6, 6],
                           [2, 2, 6, 6, 6],
                           [7, 7, 8, 8, 8],
                           [7, 7, 8, 8, 8],
                           [7, 7, 8, 8, 8]],

                          [[2, 2, 6, 6, 6],
                           [2, 2, 6, 6, 6],
                           [7, 7, 8, 8, 8],
                           [7, 7, 8, 8, 8],
                           [7, 7, 8, 8, 8]]])

        assert_array_equal(result, expected)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:54,代码来源:test_shape_base.py


示例11: test_block_complicated

    def test_block_complicated(self, block):
        # a bit more complicated
        one_2d = np.array([[1, 1, 1]])
        two_2d = np.array([[2, 2, 2]])
        three_2d = np.array([[3, 3, 3, 3, 3, 3]])
        four_1d = np.array([4, 4, 4, 4, 4, 4])
        five_0d = np.array(5)
        six_1d = np.array([6, 6, 6, 6, 6])
        zero_2d = np.zeros((2, 6))

        expected = np.array([[1, 1, 1, 2, 2, 2],
                             [3, 3, 3, 3, 3, 3],
                             [4, 4, 4, 4, 4, 4],
                             [5, 6, 6, 6, 6, 6],
                             [0, 0, 0, 0, 0, 0],
                             [0, 0, 0, 0, 0, 0]])

        result = block([[one_2d, two_2d],
                        [three_2d],
                        [four_1d],
                        [five_0d, six_1d],
                        [zero_2d]])
        assert_equal(result, expected)
开发者ID:ales-erjavec,项目名称:numpy,代码行数:23,代码来源:test_shape_base.py


示例12: test_no_lists

 def test_no_lists(self, block):
     assert_equal(block(1),         np.array(1))
     assert_equal(block(np.eye(3)), np.eye(3))
开发者ID:ales-erjavec,项目名称:numpy,代码行数:3,代码来源:test_shape_base.py


示例13: test_returns_copy

 def test_returns_copy(self, block):
     a = np.eye(3)
     b = block(a)
     b[0, 0] = 2
     assert b[0, 0] != a[0, 0]
开发者ID:ales-erjavec,项目名称:numpy,代码行数:5,代码来源:test_shape_base.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python core.concatenate函数代码示例发布时间:2022-05-27
下一篇:
Python core.atleast_3d函数代码示例发布时间: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