[問題] np.loadtxt會少項
大大好
小弟正在製作一支程式
能夠隨機產生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
推
03/16 16:57,
7年前
, 1F
03/16 16:57, 1F
→
03/16 16:58,
7年前
, 2F
03/16 16:58, 2F
→
03/16 16:59,
7年前
, 3F
03/16 16:59, 3F
Python 近期熱門文章
PTT數位生活區 即時熱門文章