Neural networks study--the difference between recording python3 and the Python2 in the textbook

Source: Internet
Author: User

After going through a lot of resumes, and decided to continue to recharge their otl, and began to learn the neural network this piece.

Found the classic textbook of deep learning. Online Address: http://neuralnetworksanddeeplearning.com

But here is python2.7, and I learned is python3, so some code can not directly exactly shown, first put on Python3 and python2 what is different.

Then record what needs to change in the course of learning:

Chapter One (identification of handwritten numerals):

1, the change of pickle

It is necessary to change the relevant code in the mnist_loader.py in the SRC folder in Mnist. First, because Python3 no longer have cpickle module, so can only use pickle, so will

Import Cpickle

Switch

Import Pickle

Corresponding, in the Load_data function:

Training_data, validation_data, test_data = Cpickle.load (f)

Also read:

Training_data, validation_data, test_data = Pickle.load (f)

However, because the load function of the pickle in Python3 has also changed, even if the file is opened in binary form, there will be an error:

' ASCII ' codec can't decode byte 0x90 in position 614:ordinal not in range (+)

This is because the default encoding in the pickle load parameter in Python3 is ASCII, so the above statement needs to be changed to:

Training_data, validation_data, Test_data = pickle.load (f,encoding="bytes")

StackOverflow on the answer to ' latin1 ', I tried the next and did not work.

2. The Zip len problem

When you run SGD in network.py, you are prompted:

Object ' Zip ' has no Len ()

This is because in Python3, the zip generates an iterator, so it cannot be used to get its length directly with Len. Instead of modifying the statement in the network, it is better to directly modify the data type of the output in Mnist_loader.

The Load_data_wrapper () will be useful to the zip statement, all zip (...) Change to List (Zip (...))

3. Range and Xrange

When you run SGD in network.py, you will be prompted:

' xrange ' is not defined

In Python2, Range generates a list directly, and xrange generates a generator. In Python3, the two are merged into a range to generate a generator, so the network.py can be useful to xrange to a range.

Neural networks study--the difference between recording python3 and the Python2 in the textbook

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.