本文整理汇总了Python中hail.linalg.BlockMatrix.fill方法的典型用法代码示例。如果您正苦于以下问题:Python BlockMatrix.fill方法的具体用法?Python BlockMatrix.fill怎么用?Python BlockMatrix.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hail.linalg.BlockMatrix
的用法示例。
在下文中一共展示了BlockMatrix.fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fill
# 需要导入模块: from hail.linalg import BlockMatrix [as 别名]
# 或者: from hail.linalg.BlockMatrix import fill [as 别名]
def test_fill(self):
nd = np.ones((3, 5))
bm = BlockMatrix.fill(3, 5, 1.0)
bm2 = BlockMatrix.fill(3, 5, 1.0, block_size=2)
self.assertTrue(bm.block_size == BlockMatrix.default_block_size())
self.assertTrue(bm2.block_size == 2)
self._assert_eq(bm, nd)
self._assert_eq(bm2, nd)
示例2: test_sum
# 需要导入模块: from hail.linalg import BlockMatrix [as 别名]
# 或者: from hail.linalg.BlockMatrix import fill [as 别名]
def test_sum(self):
def sums_agree(bm, nd):
self.assertAlmostEqual(bm.sum(), np.sum(nd))
self._assert_close(bm.sum(axis=0), np.sum(nd, axis=0, keepdims=True))
self._assert_close(bm.sum(axis=1), np.sum(nd, axis=1, keepdims=True))
nd = np.random.normal(size=(11, 13))
bm = BlockMatrix.from_numpy(nd, block_size=3)
nd2 = np.zeros(shape=(5, 7))
nd2[2, 4] = 1.0
nd2[2, 5] = 2.0
nd2[3, 4] = 3.0
nd2[3, 5] = 4.0
bm2 = BlockMatrix.from_numpy(nd2, block_size=2).sparsify_rectangles([[2, 4, 4, 6]])
bm3 = BlockMatrix.from_numpy(nd2, block_size=2).sparsify_rectangles([[2, 4, 4, 6], [0, 5, 0, 1]])
bm4 = BlockMatrix.from_numpy(nd2, block_size=2).sparsify_rectangles([[2, 4, 4, 6], [0, 1, 0, 7]])
nd5 = np.zeros(shape=(5, 7))
bm5 = BlockMatrix.fill(5, 7, value=0.0, block_size=2).sparsify_rectangles([])
sums_agree(bm, nd)
sums_agree(bm2, nd2)
sums_agree(bm3, nd2)
sums_agree(bm4, nd2)
sums_agree(bm5, nd5)
示例3: test_sum_with_sparsify
# 需要导入模块: from hail.linalg import BlockMatrix [as 别名]
# 或者: from hail.linalg.BlockMatrix import fill [as 别名]
def test_sum_with_sparsify(self):
nd = np.zeros(shape=(5, 7))
nd[2, 4] = 1.0
nd[2, 5] = 2.0
nd[3, 4] = 3.0
nd[3, 5] = 4.0
bm = BlockMatrix.from_numpy(nd, block_size=2).sparsify_rectangles([[2, 4, 4, 6]])
bm2 = BlockMatrix.from_numpy(nd, block_size=2).sparsify_rectangles([[2, 4, 4, 6], [0, 5, 0, 1]])
bm3 = BlockMatrix.from_numpy(nd, block_size=2).sparsify_rectangles([[2, 4, 4, 6], [0, 1, 0, 7]])
nd4 = np.zeros(shape=(5, 7))
bm4 = BlockMatrix.fill(5, 7, value=0.0, block_size=2).sparsify_rectangles([])
self.assert_sums_agree(bm, nd)
self.assert_sums_agree(bm2, nd)
self.assert_sums_agree(bm3, nd)
self.assert_sums_agree(bm4, nd4)