{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / util / _regular_grid / regular_grid

function

skimage.util._regular_grid:regular_grid

source: /dev/scikit-image/src/skimage/util/_regular_grid.py :4

Signature

def   regular_grid ( ar_shape n_points )

Summary

Find n_points regularly spaced along ar_shape.

Extended Summary

The returned points (as slices) should be as close to cubically-spaced as possible. Essentially, the points are spaced by the Nth root of the input array size, where N is the number of dimensions. However, if an array dimension cannot fit a full step size, it is "discarded", and the computation is done for only the remaining dimensions.

Parameters

ar_shape : array_like of dtype int

The shape of the space embedding the grid. len(ar_shape) is the number of dimensions.

n_points : int

The (approximate) number of points to embed in the space.

Returns

slices : tuple of (slice, ...)

A slice along each dimension of ar_shape, such that the intersection of all the slices give the coordinates of regularly spaced points.

Examples

ar = np.zeros((20, 40))
g = regular_grid(ar.shape, 8)
g
ar[g] = 1
ar.sum()
ar = np.zeros((20, 40))
g = regular_grid(ar.shape, 32)
g
ar[g] = 1
ar.sum()
ar = np.zeros((3, 20, 40))
g = regular_grid(ar.shape, 8)
g
ar[g] = 1
ar.sum()

Aliases

  • skimage.util.regular_grid