与Matlab textscan等价的Python
2021/7/28 17:07:42
本文主要是介绍与Matlab textscan等价的Python,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
https://www.cnpython.com/qa/83484
numpy.loadtxt
numpy.genfromtxt
将MATLAB的textscan
转换为Python+NumPy的^{}的示例:
让我们的数据文件results.csv
包含:
0.6236,sym2,1,5,10,10 0.6044,sym2,2,5,10,10 0.548,sym2,3,5,10,10 0.6238,sym2,4,5,10,10 0.6411,sym2,5,5,10,10 0.7105,sym2,6,5,10,10 0.6942,sym2,7,5,10,10 0.6625,sym2,8,5,10,10 0.6531,sym2,9,5,10,10
Matlab代码:
fileID = fopen('results.csv'); d = textscan(fileID,'%f %s %d %d %d %d', 'delimiter',','); fclose(fileID);
Python+NumPy代码:
fd = open('results2.csv','r') d = np.loadtxt(fd, delimiter=',', dtype={'names': ('col1', 'col2', 'col3', 'col4', 'col5', 'col6'), 'formats': ('float', 'S4', 'i4', 'i4', 'i4', 'i4')}) fd.close()
这篇关于与Matlab textscan等价的Python的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享