我正在从matlab
切换到python
。
我想导入的数据是这样的
4
6
2
1
2.0E8
0.2
0.002
1 2 6
2 3 4
2 4 5
2 5 6
0 0
1 0
2 0
2 1
1 1
0 1
4 0 -150
1 1 1
6 1 1
这就是我在matlab
中读到的
如何在python
中导入这些数据?我没有在python
中找到fscanf
的等价物。在
对于What is the equivalent of Matlab 'fscanf' in Python?numpy.loadtxt
需要{
遍历文件中的行,就像
parse
方法是一种将行作为输入并输出整数、浮点或整数列表的方法。在对于整数-gt;
var = int(line)
对于float->;
var = float(line)
对于INT列表->;
var = map(int, line.split())
对于矩阵->;请考虑阅读“想要一个
^{pr2}$m X n
矩阵”。 所以从上面的循环中读入m
行,就像-与
^{pr2}$Method1
相比,使用Method1
的优点是可以在method1中使用类型转换,而实现这一点的方法是使用var1 = type(var)
对于构成矩阵的第9-12行,我们可以将矩阵表示为列表列表。在
^{3}$相关问题 更多 >
编程相关推荐