作者karco (karco)
看板Python
标题[问题] np.loadtxt会少项
时间Fri Mar 16 14:26:26 2018
大大好
小弟正在制作一支程式
能够随机产生n列2行的矩阵
成功生成x.txt後
发现之後如果想要读取
利用np.loadtxt载入
载入後的列数会比原本的txt档还少
请问我哪边犯了错吗?
举例子 如下面程式码会有10000列2行
载入後 大概会只剩下97xx列2行
请问有解决的方法吗?
可以发现重新输出的out.txt范围变小了@@
程式码如下:
from random import randint
import numpy as np
a = 0
c = 0
d = 0
numbers = 10000
f = open ('x.txt', 'w')
while a < numbers:
c = float(randint(1, 90))
d = float(randint(1, 90))
e = str(c)
g = str(d)
f.write(e +' ' + g+ '\n')
a = a+1
f.close
b = np.loadtxt('x.txt').astype(np.float32)
np.savetxt('out.txt',b)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.113.121.149
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1521181589.A.253.html
1F:推 vfgce: f.close(),括号没写啦....然後,numpy 就有random可用了... 03/16 16:57
2F:→ vfgce: loadtxt本身就可以指定dtype了..... 03/16 16:58
3F:→ vfgce: 认真点查个API吧... 03/16 16:59