【发布时间】:2016-01-08 07:55:34
【问题描述】:
我有一个文本文件,其中列出了 4 x 3 二进制值:
1 0 1
0 0 1
1 1 0
0 0 1
当我在python中读取这个文件时,它是这样的形式:
import numpy as np
with open("test.txt")as g:
p=g.read().splitlines()
q=[];
for m in p:
q.append(int(m));
p=q;
Python 窗口:
>>> p
['1 0 1', '0 0 1', '1 1 0', '0 0 1']
如何转换成数组:
array([[ 1.0, 0.0, 1.0],
[ 0.0, 0.0, 1.0],
[ 1.0, 1.0, 0.0],
[ 0.0, 0.0, 1.0]])
【问题讨论】:
-
你应该看到numpy load text 我想是的。