[問題] np.loadtxt會少項

作者: karco (karco)   2018-03-16 14:26:26
大大好
小弟正在製作一支程式
能夠隨機產生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)
作者: vfgce (小兵)   2018-03-16 16:57:00
f.close(),括號沒寫啦....然後,numpy 就有random可用了...loadtxt本身就可以指定dtype了.....認真點查個API吧...

Links booklink

Contact Us: admin [ a t ] ucptt.com