本文整理汇总了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()
示例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()
示例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
示例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 ='