84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
最近在学随机过程,中间要计算矩阵,矩阵相乘太麻烦了,所以想用编程实现,也顺便练下手。基本功能已经实现,但是只能自己在程序里事先把数组输进去,所以想问一下怎样才可以通过input函数直接过去矩阵。
看了网上其他人的办法,都是这样的输入>>1 2 3 4 5
>>1 2 3 4 5
通过是split(' ')来获取得到['1','2','3''4','5']
但是我想要的是这样的的效果,这样感觉美观一些。输入:>>[ [1,2,3],[1,2,3] ]
>>[ [1,2,3],[1,2,3] ]
先谢谢啦
认证高级PHP讲师
A comparisonis not safebut the immediate solution to the problem is:
matrix = input(">>") matrix = eval(matrix) print(matrix)
Result:
>>[ [1,2,3], [1,2,3] ] [[1, 2, 3], [1, 2, 3]]
P.S. You can consider using a file to input
For example:
matrix a 1 2 3 1 2 3
Supplement: If you want to use a ready-made library to process matrices in Python, numpy is a good choice.
Isn’t it best to use Matlab to calculate matrices?
A comparisonis not safebut the immediate solution to the problem is:
Result:
P.S. You can consider using a file to input
For example:
Supplement: If you want to use a ready-made library to process matrices in Python, numpy is a good choice.
Isn’t it best to use Matlab to calculate matrices?