本文整理汇总了Python中sympy.Matrix.multiply_elementwise方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.multiply_elementwise方法的具体用法?Python Matrix.multiply_elementwise怎么用?Python Matrix.multiply_elementwise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Matrix
的用法示例。
在下文中一共展示了Matrix.multiply_elementwise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiplication
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import multiply_elementwise [as 别名]
def test_multiplication():
a=Matrix((
(1, 2),
(3, 1),
(0, 6),
))
b = Matrix ((
(1, 2),
(3, 0),
))
c= a*b
assert c[0,0]==7
assert c[0,1]==2
assert c[1,0]==6
assert c[1,1]==6
assert c[2,0]==18
assert c[2,1]==0
h = matrix_multiply_elementwise(a, c)
assert h == a.multiply_elementwise(c)
assert h[0,0]==7
assert h[0,1]==4
assert h[1,0]==18
assert h[1,1]==6
assert h[2,0]==0
assert h[2,1]==0
raises(ShapeError, 'matrix_multiply_elementwise(a, b)')
x = Symbol("x")
c = b * Symbol("x")
assert isinstance(c,Matrix)
assert c[0,0] == x
assert c[0,1] == 2*x
assert c[1,0] == 3*x
assert c[1,1] == 0
c2 = x * b
assert c == c2
c = 5 * b
assert isinstance(c,Matrix)
assert c[0,0] == 5
assert c[0,1] == 2*5
assert c[1,0] == 3*5
assert c[1,1] == 0
示例2: get_stochastic_matrix
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import multiply_elementwise [as 别名]
def get_stochastic_matrix(G):
A = nx.adjacency_matrix(G.reverse(copy=True), nodelist=list('ABCDE'))
k = Matrix((A.sum(axis=0)).astype(int)).applyfunc(lambda x: 1/x)
A = Matrix(A.astype(int))
S = A.multiply_elementwise(sympy.ones(5,1)*k)
return S