letter2number_map('A') = 1; -> equivalent to a dictionary: {'A':1}
number2letter_map(1) = 'A'; -> equivalent to a dictionary: {1:'A'}
str2num() -> maybe float(), although a look at the docs makes
it look more like eval -- Yuck.
(ast.literal_eval might be closest)
strcmp() -> I assume a simple string comparison works here.
e.g. strcmp(a,b) -> a == b
trace() -> np.trace() #sum of the diagonal
eye() -> np.eye() #identity matrix (all zeros, but 1's on diagonal)
getenv('STRING') -> os.environ['STRING'] (with os imported of course)
[MI_true, ~, ~] = function() -> Probably: MI_true,_,_ = function()
although the underscores could be any
variable name you wanted.
(Thanks Amro for providing this one)
mslice -> ??? (can't even find documentation for that one)
ones() -> np.ones() #matrix/array of all 1's
从字母转换为数字:ord("a") = 97 从数字转换为字母:chr(97) = 'a' (You可以减去96来得到你想要的结果,对于小写字母,或者对于大写字母,减去64。 将字符串解析为int:int("523") = 523 比较字符串(区分大小写):"Hello"=="Hello" = True 不区分大小写:"Hello".lower() == "hElLo".lower() = True ones():[1]*ARRAY_SIZE 单位矩阵:[[int(x==y) for x in range(5)] for y in range(5)] 要创建二维数组,需要使用numpy。 编辑: 或者,你可以像这样制作一个5x5的二维数组:[[1 for x in range(5)] for y in range(5)]
2条答案
按热度按时间dz6r00yl1#
我其实不知道matlab,但我可以回答其中的一些问题(假设你已经将numpy导入为np):
sczxawaw2#
从字母转换为数字:
ord("a") = 97
从数字转换为字母:
chr(97) = 'a'
(You可以减去96来得到你想要的结果,对于小写字母,或者对于大写字母,减去64。
将字符串解析为int:
int("523") = 523
比较字符串(区分大小写):
"Hello"=="Hello" = True
不区分大小写:
"Hello".lower() == "hElLo".lower() = True
ones()
:[1]*ARRAY_SIZE
单位矩阵:
[[int(x==y) for x in range(5)] for y in range(5)]
要创建二维数组,需要使用numpy。
编辑:
或者,你可以像这样制作一个5x5的二维数组:
[[1 for x in range(5)] for y in range(5)]