[英]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.save
, numpy.savez
或pickle
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.