How to read a text file into an array that has 0-255 values of images and split them into 784 (28x28) rows?

3583 views python
8

I have a text file that has integers ranging from 0-255 (grayscale values of images of digits) all separated by tabs. I want to read the file using pandas/numpy and arrange it into a 2D array with 1 column and the number of rows corresponding to the number of sample images I have. So each row would have 784 integers (28X28 pixel values of an image flattened). So basically split the text file into chunks of 784 integers.

answered question

Hello and Welcome to StackOverflow! :-) It would be nice to see the input and the code you're having problems with. Please have a look at How do I ask a good question? and edit your question.

1 Answer

7

I want to read the file using pandas/numpy and arrange it into a 2D array with 1 column

So each row would have 784 integers

If you want each row to have 784 integers, then you want 784 columns.

You can probably do something like this:

images = pd.read_csv(<filename>, sep="\t", header=None)

posted this

Have an answer?

JD

Please login first before posting an answer.