本文整理汇总了Python中sympy.tensor.array.dense_ndim_array.ImmutableDenseNDimArray.tomatrix方法的典型用法代码示例。如果您正苦于以下问题:Python ImmutableDenseNDimArray.tomatrix方法的具体用法?Python ImmutableDenseNDimArray.tomatrix怎么用?Python ImmutableDenseNDimArray.tomatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.tensor.array.dense_ndim_array.ImmutableDenseNDimArray
的用法示例。
在下文中一共展示了ImmutableDenseNDimArray.tomatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ndim_array_converting
# 需要导入模块: from sympy.tensor.array.dense_ndim_array import ImmutableDenseNDimArray [as 别名]
# 或者: from sympy.tensor.array.dense_ndim_array.ImmutableDenseNDimArray import tomatrix [as 别名]
def test_ndim_array_converting():
dense_array = ImmutableDenseNDimArray([1, 2, 3, 4], (2, 2))
alist = dense_array.tolist()
alist == [[1, 2], [3, 4]]
matrix = dense_array.tomatrix()
assert (isinstance(matrix, Matrix))
for i in range(len(dense_array)):
assert dense_array[i] == matrix[i]
assert matrix.shape == dense_array.shape
assert ImmutableDenseNDimArray(matrix) == dense_array
assert ImmutableDenseNDimArray(matrix.as_immutable()) == dense_array
assert ImmutableDenseNDimArray(matrix.as_mutable()) == dense_array
sparse_array = ImmutableSparseNDimArray([1, 2, 3, 4], (2, 2))
alist = sparse_array.tolist()
assert alist == [[1, 2], [3, 4]]
matrix = sparse_array.tomatrix()
assert(isinstance(matrix, SparseMatrix))
for i in range(len(sparse_array)):
assert sparse_array[i] == matrix[i]
assert matrix.shape == sparse_array.shape
assert ImmutableSparseNDimArray(matrix) == sparse_array
assert ImmutableSparseNDimArray(matrix.as_immutable()) == sparse_array
assert ImmutableSparseNDimArray(matrix.as_mutable()) == sparse_array