Skip to main content

Save and load numpy arrays as PNG images

Project description

imgarray (Python)

This stores 1D and 2D numpy arrays as png images. As a method of storage, not visualization (use pillow for that).

Q: Why would you ever want that?

  • It’s somewhat, though not extremely, space-efficient.

  • Saving and loading PNGs is supported by many languages, so all you need to do is port this library.

  • Results look kind of funny, nothing too interesting though.

  • Because you can.



This package requires numpy and pillow. They will be installed automatically if you install using pip:

pip install imgarray


Usage is very simple, there are only two functions:

from imgarray import save_array_img, load_array_img
data = randn((500, 500)).astype(int16)
save_array_img(data, path)
data2 = load_array_img(path)

You can check out or the tests for more (not a lot more to be fair, it’s a simple tool).


  • 1D arrays will be returned as 2D arrays with one unit dimension, because images are 2D.

  • It works with most numpy data types (specifically, the ones that use a number of bytes which is a power of 2).

  • If you remove metadata from the PNG, the file only loads correctly if the data was float64, and you’ll also get a warning.

  • If the data has more or less than 4 bytes per value, the height of the image is scaled to match. So array shape and image shape are similar but not necessarily identical.

Usage & contributions

Revised BSD License; at your own risk, you can mostly do whatever you want with this code, just don’t use my name for promotion and do keep the license file.

Pull requests are welcome, especially with unit tests. Due to the great importance of this library, maintenance is not going to be high-priority.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imgarray-1.0.tar.gz (4.5 kB view hashes)

Uploaded source

Built Distribution

imgarray-1.0-py2.py3-none-any.whl (6.9 kB view hashes)

Uploaded 2 7

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page