Skip to content

npyfile: Write arrays continuously to .npy files

License

Notifications You must be signed in to change notification settings

maxstrobel/npyfile

Repository files navigation

npyfile: Write arrays continuously to .npy files

Documentation Status CI Status

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

About

npyfile: Write arrays continuously to .npy files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages