MCPcopy Create free account
hub / github.com/dask/dask / trim

Function trim

dask/array/chunk.py:151–170  ·  view source on GitHub ↗

Trim boundaries off of array >>> x = np.arange(24).reshape((4, 6)) >>> trim(x, axes={0: 0, 1: 1}) array([[ 1, 2, 3, 4], [ 7, 8, 9, 10], [13, 14, 15, 16], [19, 20, 21, 22]]) >>> trim(x, axes={0: 1, 1: 1}) array([[ 7, 8, 9, 10],

(x, axes=None)

Source from the content-addressed store, hash-verified

149
150
151def trim(x, axes=None):
152 """Trim boundaries off of array
153
154 >>> x = np.arange(24).reshape((4, 6))
155 >>> trim(x, axes={0: 0, 1: 1})
156 array([[ 1, 2, 3, 4],
157 [ 7, 8, 9, 10],
158 [13, 14, 15, 16],
159 [19, 20, 21, 22]])
160
161 >>> trim(x, axes={0: 1, 1: 1})
162 array([[ 7, 8, 9, 10],
163 [13, 14, 15, 16]])
164 """
165 if isinstance(axes, Integral):
166 axes = [axes] * x.ndim
167 if isinstance(axes, dict):
168 axes = [axes.get(i, 0) for i in range(x.ndim)]
169
170 return x[tuple(slice(ax, -ax if ax else None) for ax in axes)]
171
172
173def topk(a, k, axis, keepdims):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected