pythonで<!DOCTYPE html>に対してエラーが出ます.解決策を教えていただきたいです. 自分はpython初心者で本を参考にしながら勉強しているところです.
pythonで<!DOCTYPE html>に対してエラーが出ます.解決策を教えていただきたいです. 自分はpython初心者で本を参考にしながら勉強しているところです. その参考書とまったく同じように動かしているのですがどうもうまくいきません. エラーは以下の通りです. C:\python\ch3>python mnist_show.py Traceback (most recent call last): File "mnist_show.py", line 5, in <module> File "..\dataset\mnist.py", line 7 <!DOCTYPE html> ^ SyntaxError: invalid syntax 実行したmnist_show.pyは以下の通りです(著者から提供されているもので自分はいじってはいません) カウントディレクトリはpython/ch3, 途中でインポートするmnist.pyはpython/datasetにあります. # coding: utf-8 import sys, os sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定 import numpy as np from dataset.mnist import load_mnist from PIL import Image def img_show(img): pil_img = Image.fromarray(np.uint8(img)) pil_img.show() (x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False) img = x_train[0] label = t_train[0] print(label) # 5 print(img.shape) # (784,) img = img.reshape(28, 28) # 形状を元の画像サイズに変形 print(img.shape) # (28, 28) img_show(img) また,mnist.pyも著者から提供されているもので中身は以下から見られます. https://github.com/oreilly-japan/deep-learning-from-scratch/tree/master/dataset
ベストアンサー
ID非公開
ID非公開さん
2017/3/2 1:32
自分の環境 (Mac, python3) では問題なく動作しました. また github の全ファイル内から "DOCTYPE" を検索してみましたが, 見つかりませんでした. どこかに誤って <!DOCTYPE html> を記述していませんか? 特に "..\dataset\mnist.py", line 7 のあたりはどうですか?
1人がナイス!しています