Skip to content

Commit 5542657

Browse files
committed
Add example to docstring.
1 parent f6ffb8a commit 5542657

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tiled/client/array.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def write_block(self, array, block, slice=...):
183183

184184
def patch(self, array: NDArray, slice: NDSlice, extend=False):
185185
"""
186-
Write data
186+
Write data into a slice of an array, maybe extending the shape.
187187
188188
Parameters
189189
----------
@@ -193,6 +193,45 @@ def patch(self, array: NDArray, slice: NDSlice, extend=False):
193193
Where to place this data in the array
194194
extend : bool
195195
Extend the array shape to fit the new slice, if necessary
196+
197+
Examples
198+
--------
199+
200+
Create a (3, 2, 2) array of ones.
201+
202+
>>> ac = c.write_array(numpy.ones((3, 2, 2)), key='y')
203+
>>> ac
204+
<ArrayClient shape=(3, 2, 2) chunks=((3,), (2,), (2,)) dtype=float64>
205+
206+
Read it.
207+
208+
>>> ac.read()
209+
array([[[1., 1.],
210+
[1., 1.]],
211+
212+
[[1., 1.],
213+
[1., 1.]],
214+
215+
[[1., 1.],
216+
[1., 1.]]])
217+
218+
Extend the array by concatenating a (1, 2, 2) array of zeros.
219+
220+
>>> ac.patch(numpy.zeros((1, 2, 2)), slice=slice(3, 4), extend=True)
221+
222+
Read it.
223+
224+
>>> array([[[1., 1.],
225+
[1., 1.]],
226+
227+
[[1., 1.],
228+
[1., 1.]],
229+
230+
[[1., 1.],
231+
[1., 1.]],
232+
233+
[[0., 0.],
234+
[0., 0.]]])
196235
"""
197236
array_ = numpy.ascontiguousarray(array)
198237
params = params_from_slice(slice)

0 commit comments

Comments
 (0)