-2

To begin my study about neural network I try to learn about mnist dataset. I learn from http://yann.lecun.com/exdb/mnist/ website. Then I want to try convert the dataset into csv file. As I know there are csv files on the internet, but I want to try convert it by myself. I got some tutorials from the internet and this is the source code (from https://pjreddie.com/projects/mnist-in-csv/)

def convert(imgf, labelf, outf, n):
    f = open(imgf, "rb")
    o = open(outf, "w")
    l = open(labelf, "rb")

    f.read(16)
    l.read(8)
    images = []

    for i in range(n):
        image = [ord(l.read(1))]
        for j in range(28 * 28):
            image.append(ord(f.read(1)))
        images.append(image)

    for image in images:
        o.write(",".join(str(pix) for pix in image) + "\n")
    f.close()
    o.close()
    l.close()

convert("train-images-idx3-ubyte", "train-labels-idx1-ubyte", "mnist_train.csv", 60000)
convert("t10k-images-idx3-ubyte", "t10k-labels-idx1-ubyte", "mnist_test.csv", 10000)

But I have an error like this:

TypeError: ord() expected a character, but string of length 0 found

Its refer to ord(f.read(1)). How to solve it? I use python 3.5

dev-x
  • 897
  • 3
  • 15
  • 30
  • What is going on with this question? The question in its original form has nothing to do with its current form, AFAICanTell. The current form is succinct and completely answerable, and is the problem I'm actually looking to resolve. But now I'm disappointed to find the question had nothing to do with what I'm actually trying to figure out. Please put the question back to its original form so Google might quit associating it with my search. Maybe I have that power... – GG2 May 10 '18 at 02:41

1 Answers1

3

You could do something like this to view relationships between all the data:

import seaborn as sns
from sklearn import datasets
import matplotlib.pyplot as plt

iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
_ = sns.pairplot(data=df)
plt.show()

enter image description here

Scott Boston
  • 147,308
  • 15
  • 139
  • 187