当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.tolist方法代码示例

本文整理汇总了Python中sympy.Matrix.tolist方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.tolist方法的具体用法?Python Matrix.tolist怎么用?Python Matrix.tolist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.Matrix的用法示例。


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

示例1: MatrizInversa

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import tolist [as 别名]
def MatrizInversa(a, b,lista):
    
    ma = json.loads(a)
    
    mb = json.loads(b)
    
    A = Matrix(ma)
    
    B = Matrix(mb)
    
    try:
    
        A_inv = A.inv()
    
    except ValueError:
    
        lista.append('\n')
    
        lista.append( 'Matriz es singular, no se puede resolver!')
    
        lista.append('\n') 
    
    else:
    
        ans = A_inv*B
    
        MA = A.tolist()
    
        MB = B.tolist()
开发者ID:Guillermo2013,项目名称:ProyectoMetodosNumericos,代码行数:31,代码来源:MatrizInversa.py

示例2: test_matrix_tensor_product

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import tolist [as 别名]
    def test_matrix_tensor_product():
        l1 = zeros(4)
        for i in range(16):
            l1[i] = 2**i
        l2 = zeros(4)
        for i in range(16):
            l2[i] = i
        l3 = zeros(2)
        for i in range(4):
            l3[i] = i
        vec = Matrix([1,2,3])

        #test for Matrix known 4x4 matricies
        numpyl1 = np.matrix(l1.tolist())
        numpyl2 = np.matrix(l2.tolist())
        numpy_product = np.kron(numpyl1,numpyl2)
        args = [l1, l2]
        sympy_product = matrix_tensor_product(*args)
        assert numpy_product.tolist() == sympy_product.tolist()
        numpy_product = np.kron(numpyl2,numpyl1)
        args = [l2, l1]
        sympy_product = matrix_tensor_product(*args)
        assert numpy_product.tolist() == sympy_product.tolist()

        #test for other known matrix of different dimensions
        numpyl2 = np.matrix(l3.tolist())
        numpy_product = np.kron(numpyl1,numpyl2)
        args = [l1, l3]
        sympy_product = matrix_tensor_product(*args)
        assert numpy_product.tolist() == sympy_product.tolist()
        numpy_product = np.kron(numpyl2,numpyl1)
        args = [l3, l1]
        sympy_product = matrix_tensor_product(*args)
        assert numpy_product.tolist() == sympy_product.tolist()

        #test for non square matrix
        numpyl2 = np.matrix(vec.tolist())
        numpy_product = np.kron(numpyl1,numpyl2)
        args = [l1, vec]
        sympy_product = matrix_tensor_product(*args)
        assert numpy_product.tolist() == sympy_product.tolist()
        numpy_product = np.kron(numpyl2,numpyl1)
        args = [vec, l1]
        sympy_product = matrix_tensor_product(*args)
        assert numpy_product.tolist() == sympy_product.tolist()

        #test for random matrix with random values that are floats
        random_matrix1 = np.random.rand(np.random.rand()*5+1,np.random.rand()*5+1)
        random_matrix2 = np.random.rand(np.random.rand()*5+1,np.random.rand()*5+1)
        numpy_product = np.kron(random_matrix1,random_matrix2)
        args = [Matrix(random_matrix1.tolist()),Matrix(random_matrix2.tolist())]
        sympy_product = matrix_tensor_product(*args)
        assert not (sympy_product - Matrix(numpy_product.tolist())).tolist() > \
        (ones((sympy_product.rows,sympy_product.cols))*epsilon).tolist()

        #test for three matrix kronecker
        sympy_product = matrix_tensor_product(l1,vec,l2)

        numpy_product = np.kron(l1,np.kron(vec,l2))
        assert numpy_product.tolist() == sympy_product.tolist()
开发者ID:Aang,项目名称:sympy,代码行数:62,代码来源:test_matrixutils.py

示例3: test_tolist

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import tolist [as 别名]
def test_tolist():
    x, y, z = symbols('xyz')
    lst = [[S.One,S.Half,x*y,S.Zero],[x,y,z,x**2],[y,-S.One,z*x,3]]
    m = Matrix(lst)
    assert m.tolist() == lst
开发者ID:Lucaweihs,项目名称:sympy,代码行数:7,代码来源:test_matrices.py

示例4: raw_input

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import tolist [as 别名]
a = raw_input('Introduzca la matriz A = ')
ma = json.loads(a)
b = raw_input('Introduzca el vector B = ')
mb = json.loads(b)

A = Matrix(ma)
B = Matrix(mb)
try:
    A_inv = A.inv()
except ValueError:
    print
    print 'Matriz es singular, no se puede resolver!'
    print
else:
    ans = A_inv*B
    MA = A.tolist()
    MB = B.tolist()
    MA_inv = A_inv.tolist()
    M_ans = ans.tolist()

    print
    print 'Matriz A = '
    print'\t|   '+('|\n\t|   '.join([''.join(['{:4}'.format(item) for item in row]) for row in MA]))+'|'
    print
    print 'Vector B = '
    print '\t|   '+('|\n\t|   '.join([''.join(['{:4}'.format(item) for item in row]) for row in MB]))+'|'
    print
    print 'Matriz Inversa de A^-1 ='
    print '\t|   '+('\t|\n\t|   '.join(['\t'.join(['{:4}'.format(item) for item in row]) for row in MA_inv]))+'\t|'
    print
    print 'Respuesta A^-1 * B ='
开发者ID:WilliamAvila,项目名称:ProyectoMetodosNumericos,代码行数:33,代码来源:MatrizInversa.py


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