title: Store 2D Array in .png format with colours
body: <p>I wrote this Python Program to create and save a matrix (2D Array) to a .png file. The program compiles and runs without any error. Even the IMAGE.png file is created but the png file won't open. When I try to open it in MSPaint, it says:</p>
  
  <blockquote>
    <p>Cannot open image. Not a valid bitmap file or its format is not currently supported.</p>
  </blockquote>
  
  <p>My objective is to create a RBG png image based on the numbers stored in the 2D Array.</p>
  
  <p>Source Code:</p>
  
  <pre><code>    import numpy;
      import png;
  
      imagearray = numpy.zeros(shape=(512,512));
  
      /* Code to insert one '1', '2', '3' in certain locations 
         of the numpy 2D Array. Rest of the location by default stores zero '0'.*/
  
  
      f = open("IMAGE.png", 'wb');
      f.write(imagearray);
      f.close();
  </code></pre>
  
  <p>I don't understand where I went wrong as there is no error message. Please Help.</p>
  
  <p>PS- I just want to save the matrix as an image file, so if you have a better and easy way of doing it in Python2.7, do suggest.</p>