Skip to main content

NumPy File

Project description

npyfile is a a package that allows you to continuously write arrays to a .npy file. You can use it like a standard Python file with the well-known context manager.

Warning: Due to the internal structure of .npy files, the arrays must have the same shape & dtype.

Example

Generate some artificial dummy data, e.g. images, & write them into a temporary file. A real world scenario reflecting this is the continuous arrival of new images from a camera.

import pathlib
import tempfile
tmp_dir = tempfile.TemporaryDirectory()
outfile = pathlib.Path(tmp_dir.name) / 'images.npy'

images = np.random.randint(low=0, high=255, size=(10,640,480,3))

with NpyFile(outfile) as file:
    for img in images:
        file.write(img)

np.testing.assert_array_equal(images, np.load(outfile))

tmp_dir.cleanup()

Credits

  • attrs: Project & infrastructure setup

  • numpy: File format

Project details


Download files

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

Source Distribution

npyfile-1.0.0.tar.gz (10.5 kB view hashes)

Uploaded Source

Built Distribution

npyfile-1.0.0-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

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