简体   繁体   English

如何在Python中从文本文件导入矩阵

[英]How to import a Matrix from a text file in Python

Hey this might be a simple question, but I have never had to import any files into Python before. 嘿,这可能是一个简单的问题,但是我以前从未不必将任何文件导入Python。

So I have a numpy Matrix in a text file, named dmatrix.txt , so how would I be able to import the file into Python and use the matrix? 因此,我在名为dmatrix.txt的文本文件中有一个numpy Matrix,那么如何将文件导入Python并使用该矩阵?

I am trying to use numpy.load() , but I am unsure how to use it. 我正在尝试使用numpy.load() ,但是我不确定如何使用它。

Try numpy.loadtxt('dmatrix.txt') ; 尝试numpy.loadtxt('dmatrix.txt') ; you could add a delimiter argument if the file is comma-separated or something. 如果文件是逗号delimiter则可以添加delimiter参数。

numpy.load is for files in numpy/python binary formats - created by numpy.save , numpy.savez , or pickle . numpy.load适用于numpy / python二进制格式的文件-由numpy.savenumpy.savezpickle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM