gpt4 book ai didi

python - 当我从 python 中的文本文件加载数据时出错

转载 作者:行者123 更新时间:2023-11-30 22:56:56 25 4
gpt4 key购买 nike

我对 Linux、Python 和 Tensorflow 完全陌生。我在从单独的文本文件获取数据时遇到问题。Python编码如下。

import tensorflow as tf
import numpy as np

xy=np.loadtxt('train.txt',unpack=True, dtype='float32')

x_data=xy[0:-1]
y_data=xy[-1];

print 'x',x_data
print 'y',y_data

错误信息如下。

root@bu-R470-R420:/home/bu# source ~/tensorflow/bin/activate
tensorflow)root@bu-R470-R420:/home/bu# python -m tensorflow.linearLoad
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/root/tensorflow/lib/python2.7/site-packages/tensorflow/linearLoad.py", line 5, in <module>
xy=np.loadtxt('train.txt',unpack=True, dtype='float32')
File "/root/tensorflow/local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 803, in loadtxt
fh = iter(open(fname, 'U'))
IOError: [Errno 2] No such file or directory: 'train.txt'
(tensorflow)root@bu-R470-R420:/home/bu#

由于我一直使用 Windows 操作系统,因此在 Linux 中编码是一场噩梦。请帮帮我。

最佳答案

您收到的 IOError 异常意味着相对路径中不存在文件 train.txt

错误消息清楚地表明了这一点:

IOError: [Errno 2] No such file or directory: 'train.txt'

仔细检查文件train.txt是否存在于您运行脚本的文件夹中,在您的情况下为/home/bu

关于python - 当我从 python 中的文本文件加载数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36879429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com