0

I have a 784 element 1-dimensional array that is a flattened 28x28 image.

Is there a nice, snappy, numpy/scipy procedure for translating that 784 element array into a 28x28 array?

Or do I have to do:

for i in range(0,28):
    for j in range(0,28):
           my_image[i,j] = oneD_vector[28*i + j]
Chris
  • 28,822
  • 27
  • 83
  • 158
  • have you seen numpy.reshape: http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.reshape.html – Garrett R Feb 05 '16 at 23:22

1 Answers1

4

reshape() works:

a = np.arange(784)
a.reshape(28, 28)
Mike Müller
  • 82,630
  • 20
  • 166
  • 161