Skip to content

How to open a NDArray for read and write? #177

Closed

Description

@Karol-G

Hey,

I am having difficulties understanding the documentation on how to create a peristent NDArray on disk that is populated slice-wise with data over time. The same goes vice-versa with reading from the NDArray on the disk.

With Zarr I would approach it like this:

Writing:

import zarr
import numpy

array_zarr = zarr.open("tmp.zarr", shape=(10, ), dtype=np.float32, chunks=(2, ), mode='w')
array_zarr[:5] = [1, 2, 1, 2, 1]
array_zarr[5:] = [3, 4, 3, 4, 3]

Reading:

import zarr
import numpy

array_zarr = zarr.open("tmp.zarr", mode='r')
array = np.zeros((10, ))
array[:5] = array_zarr[:5]
array[5:] = array_zarr[5:]

How do I do the same with blosc2?

Best regards,
Karol

Activity

  1. FrancescAlted commented on Mar 27, 2024

    @FrancescAlted
    Member

    Sure. Following the tutorial should help you grasping the basics for persistence and slicing: https://www.blosc.org/python-blosc2/getting_started/tutorials/02.ndarray-basics.html

    For creating an empty array (the equivalent of open in zarr), you can use blosc2.empty() with a urlpath as keyword argument.

    BTW, the documentation can be improved for sure. If you think that you can contribute to the cause, we would gladly accept PRs.

  2. locked and limited conversation to collaborators on Mar 27, 2024
  3. converted this issue into a discussion #178 on Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions