看板 Python 關於我們 聯絡資訊
大大好 小弟正在製作一支程式 能夠隨機產生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://www.ptt.cc/bbs/Python/M.1521181589.A.253.html
vfgce: f.close(),括號沒寫啦....然後,numpy 就有random可用了... 03/16 16:57
vfgce: loadtxt本身就可以指定dtype了..... 03/16 16:58
vfgce: 認真點查個API吧... 03/16 16:59