質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

PyCharm

エディター・開発ツール

Q&A

解決済

1回答

388閲覧

mnistの読み込み時のエラーについて

cand

総合スコア65

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

PyCharm

エディター・開発ツール

0グッド

0クリップ

投稿2018/08/04 05:23

python

1import sys,os 2os.chdir("C:\Users\keigo\Documents\python\Deep Learning\dataset") 3sys.path.append(os.pardir) 4from dataset.mnist import load_mnist 5 6(x_train, t_train), (x_test, t_test) = \ 7load_mnist(flatten=True, normalize=False) 8 9print(x_train.shape) 10print(t_train.shape) 11print(x_test.shape) 12print(t_test.shape)

このようにしましたが、

"C:\Users\keigo\Documents\python\Deep Learning\venv\Scripts\python.exe" "C:\Users\keigo\Documents\python\Deep Learning\3.6.1.py"
File "C:\Users\keigo\Documents\python\Deep Learning\3.6.1.py", line 2
os.chdir("C:\Users\keigo\Documents\python\Deep Learning\dataset")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Process finished with exit code 1

というエラーが出ました。
なぜでしょうか。

os.chdir()でファイルのパスはとおしています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

エスケープシーケンスと認識されているので、raw文字列を使ってください。

Python

1os.chdir(r"C:\Users\keigo\Documents\python\Deep Learning\dataset")

os.chdir()でファイルのパスはとおしています

通ってないです。確かに通そうとはしていますが、そこでエラーが起きているのです。
トレースバックを眺める癖を付けましょう。

投稿2018/08/04 05:26

編集2018/08/04 05:33
LouiS0616

総合スコア35658

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

cand

2018/08/04 06:24

ありがとうございます
cand

2018/08/04 11:24

やってみました 今度は "C:\Users\keigo\Documents\python\Deep Learning\venv\Scripts\python.exe" "C:/Users/keigo/Documents/python/Deep Learning/3.6.1.py" Traceback (most recent call last): File "C:/Users/keigo/Documents/python/Deep Learning/3.6.1.py", line 7, in <module> load_mnist(flatten=True, normalize=False) File "C:\Users\keigo\Documents\python\Deep Learning\dataset\mnist.py", line 106, in load_mnist Converting train-images-idx3-ubyte.gz to NumPy Array ... init_mnist() File "C:\Users\keigo\Documents\python\Deep Learning\dataset\mnist.py", line 76, in init_mnist dataset = _convert_numpy() File "C:\Users\keigo\Documents\python\Deep Learning\dataset\mnist.py", line 67, in _convert_numpy dataset['train_img'] = _load_img(key_file['train_img']) File "C:\Users\keigo\Documents\python\Deep Learning\dataset\mnist.py", line 59, in _load_img data = np.frombuffer(f.read(), np.uint8, offset=16) File "C:\Users\keigo\AppData\Local\Programs\Python\Python36\lib\gzip.py", line 276, in read return self._buffer.read(size) File "C:\Users\keigo\AppData\Local\Programs\Python\Python36\lib\gzip.py", line 482, in read raise EOFError("Compressed file ended before the " EOFError: Compressed file ended before the end-of-stream marker was reached Process finished with exit code 1 こんなエラーが出ます なぜでしょうか
LouiS0616

2018/08/04 11:37

train-images-idx3-ubyte.gzはどこかから落としてきたファイルですか? データが壊れているかもしれませんので、もう一度ダウンロードして置き換えてみてください。
cand

2018/08/04 11:56

はい
cand

2018/08/04 11:57

mnist.pyというファイルを実行してダウンロードしたフォルダです
cand

2018/08/04 12:01

ダウンロードした後に再起動していなかったのが問題だったようです。 回答ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問