簡體   English   中英

即使在文件中有值,為什么在python中導入文本文件時也將其返回為空?

[英]Why do my text files return as empty when I import it in python even though there are values in the file?

我嘗試加載其中包含300000個整數的文本文件。 我使用以下代碼加載文本:

import numpy as np 
x = np.loadtxt("signal.txt", delimiter=",")
print(x)

當我嘗試打印這些值時,它們返回空值。 我該如何解決這個問題? 我檢查了數據集中是否有值,並且它們在那里。

該測試用例應在您的系統上順利運行。 如果是這樣,則您的原始signals.txt文件應該有問題。...字符...編碼...

import numpy as np
import random

# generate file with 0s and 1s
with open('test.txt', 'w') as f:
    text = ', '.join([str(random.randint(0,1)) for _ in range(1000)])
    f.write(text)

array = np.loadtxt('test.txt', delimiter=',')
print(array.shape)
array

# to check signals.txt  ... print content
with open('signals.txt') as f:
    text = f.read()
    print(text)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM