title: Convert a black and white image to array of numbers?
body: <p><a href="https://i.stack.imgur.com/gC1x7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gC1x7.png" alt="The image is 28 pixels by 28 pixels. They can interpret this as a big array of numbers:"></a>
  Like the image above suggests, how can I convert the image to the left into an array that represent the darkness of the image between <code>0 for white</code> and <code>decimals for darker colours closer to 1? as shown in the image using</code>python 3`? </p>
  
  <p>Update:
  I have tried to work abit more on this. There are good answers below too.</p>
  
  <pre><code># Load image 
  filename = tf.constant("one.png")
  image_file = tf.read_file(filename)
  
  # Show Image
  Image("one.png")
  
  #convert method
  def convertRgbToWeight(rgbArray):
      arrayWithPixelWeight = []
      for i in range(int(rgbArray.size / rgbArray[0].size)):
          for j in range(int(rgbArray[0].size / 3)):
              lum = 255-((rgbArray[i][j][0]+rgbArray[i][j][1]+rgbArray[i][j][2])/3) # Reversed luminosity
              arrayWithPixelWeight.append(lum/255) # Map values from range 0-255 to 0-1
  
      return arrayWithPixelWeight
  
  
  
  # Convert image to numbers and print them
  image_decoded_png = tf.image.decode_png(image_file,channels=3)
  image_as_float32 = tf.cast(image_decoded_png, tf.float32)
  
  numpy.set_printoptions(threshold=numpy.nan)
  sess = tf.Session()
  squeezedArray = sess.run(image_as_float32)
  
  convertedList = convertRgbToWeight(squeezedArray)
  
  print(convertedList) # This will give me an array of numbers. 
  </code></pre>