本文整理汇总了Python中sympy.Matrix.astype方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.astype方法的具体用法?Python Matrix.astype怎么用?Python Matrix.astype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Matrix
的用法示例。
在下文中一共展示了Matrix.astype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_stochastic_matrix
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import astype [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
示例2: print
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import astype [as 别名]
#transform message array to matrix
message.resize(int(message_length/key_rows), key_rows)
#------------------------
encryption = np.matmul(message, key)
encryption = np.remainder(encryption, module)
print("encrypted text: \n",encryption)
#------------------------
#decryption
#------------------------
print("finding inverse key")
inverse_key = Matrix(key).inv_mod(module)
inverse_key = np.array(inverse_key) #sympy to numpy
inverse_key = inverse_key.astype(float)
print("inverse key: ",inverse_key)
#------------------------
print("validating inverse key. key times inverse key must be idendity matrix")
check = np.matmul(key, inverse_key)
check = np.remainder(check, module)
print("key times inverse key: ",check)
print("it is ",np.allclose(check, np.eye(3)))
#------------------------
print("decryption:")
decryption = np.matmul(encryption, inverse_key)
decryption = np.remainder(decryption, module).flatten()
print("decryption: ",decryption)