Skip to content

Commit

Permalink
Add example to docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Nov 1, 2024
1 parent fad0073 commit bc55357
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tiled/client/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def write_block(self, array, block, slice=...):

def patch(self, array: NDArray, slice: NDSlice, extend=False):
"""
Write data
Write data into a slice of an array, maybe extending the shape.
Parameters
----------
Expand All @@ -193,6 +193,45 @@ def patch(self, array: NDArray, slice: NDSlice, extend=False):
Where to place this data in the array
extend : bool
Extend the array shape to fit the new slice, if necessary
Examples
--------
Create a (3, 2, 2) array of ones.
>>> ac = c.write_array(numpy.ones((3, 2, 2)), key='y')
>>> ac
<ArrayClient shape=(3, 2, 2) chunks=((3,), (2,), (2,)) dtype=float64>
Read it.
>>> ac.read()
array([[[1., 1.],
[1., 1.]],
[[1., 1.],
[1., 1.]],
[[1., 1.],
[1., 1.]]])
Extend the array by concatenating a (1, 2, 2) array of zeros.
>>> ac.patch(numpy.zeros((1, 2, 2)), slice=slice(3, 4), extend=True)
Read it.
>>> array([[[1., 1.],
[1., 1.]],
[[1., 1.],
[1., 1.]],
[[1., 1.],
[1., 1.]],
[[0., 0.],
[0., 0.]]])
"""
array_ = numpy.ascontiguousarray(array)
params = params_from_slice(slice)
Expand Down

0 comments on commit bc55357

Please sign in to comment.