0

Im in python, I have a list with a length 784 (which i extracted from a 28x28 image ) and now i want to arrange it in a way i can use it in tensor-flow to be used with a trained model but the problem is that the NN needs to have a 28,28 shaped array but my current array is of shape (784,)

I tried to use some for loops for this but i have no luck in successfully creating a system to carry this out , please help

i figured out that i need to use this structure

for i in range(res):
   for a in range(0,res):

       mnistFormat.append(grascalePix[a]) #mnistFormat is an innitially empty list
#and grascale has my 784 grayscale pixles

but i cant figure out what should go in the range function of the for loop to make this possible

For example lets say i have a sample 4x4 image's pixel list >

grayscalePix = [255,255,255,255,255,100,83,200,255,50,60,255,30,1,46,255]

this is a Row by Row representation , which means the first 4 elements are the first ---- row

i want to arrange them into a list of shape (4,4) mnistFormat = [255,255,255,255],[255,100,83,200],[255,50,60,255],[30,1,46,255]

Just keep in mind this is sample , the real data is 784 elements long and i dont have much experince in numpy

  • Does this answer your question? [Reshape an array in NumPy](https://stackoverflow.com/questions/14476415/reshape-an-array-in-numpy) – buran Jan 12 '21 at 14:04

1 Answers1

1

numpy might help you there very easily:

mnistFormat = np.array(grascalePix).reshape((np.sqrt(len()),-1))
adir abargil
  • 5,495
  • 3
  • 19
  • 29