我一直在尝试将python代码转换为Matlab脚本,但我确实需要一些帮助。我对编程世界相当陌生,因为我不知道不同的命令
我曾试图逐字转换,但我失败得很惨:(
def ranking(A):
import numpy as np
from mat1120lib import null
if (A.shape[0] == A.shape[1] and len(A.shape) == 2):
n = A.shape[0]
else:
n=0
print "A is not a square matrix,aborting!"
import sys
sys.exit(1)
tol = 1e-12
for i in range(n);
if (np.sum(A.T[i])-)>tol:
print "A is not a stochastic matrix, aborting!"
import sys
sys.exit(1)
S=1/float(n) * np.ones((n,n))
m=0.15
M=(1-m)*A + m*S
n=null(M-np.eye(n))
return n/np.sum(n)
下面是在MATLAB中复制功能的粗略尝试。如另一个答案所述,可以获得排名
如果你真的想得到矩阵的秩,你可以简单地使用Matlab内置函数
正如您所说,逐行翻译代码是一种可能性,在我看来,由于图片上的函数相对较短,可能是解决问题的最快方法
关于为什么源代码转换器不那么常见,请检查以下线程: Why aren't there automated translators from one programming language to another? [closed]
Edit01:我对整段代码进行了注释,并解释了每行代码的作用,如下所示。我希望它能帮助您理解Python中的代码
相关问题 更多 >
编程相关推荐