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


Python Matrix.astype方法代码示例

本文整理汇总了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
开发者ID:SGo-Go,项目名称:docs,代码行数:8,代码来源:rand_surf.py

示例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)
开发者ID:serengil,项目名称:crypto,代码行数:32,代码来源:hill.py


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