code: def imsave(filename, data, maxval=None, pam=False):
      
      try:
          netpbm = NetpbmFile(data, maxval=maxval)
          netpbm.write(filename, pam=pam)
      finally:
          netpbm.close()
docs: Write image data to Netpbm file.
  
      Examples
      --------
      >>> image = numpy.array([[0, 1],[65534, 65535]], dtype=numpy.uint16)
      >>> imsave('_tmp.pgm', image)