apply_along_axis(func1d, axis, arr, *args, dtype=None, shape=None, **kwargs)
This docstring was copied from numpy.apply_along_axis.
Some inconsistencies with the Dask version may exist.
This is a blocked variant of numpy.apply_along_axis
implemented via dask.array.map_blocks
If either of :None:None:`dtype`
or shape
are not provided, Dask attempts to determine them by calling :None:None:`func1d`
on a dummy array. This may produce incorrect values for :None:None:`dtype`
or shape
, so we recommend providing them.
Execute :None:None:`func1d(a, *args, **kwargs)`
where :None:None:`func1d`
operates on 1-D arrays and a
is a 1-D slice of :None:None:`arr`
along :None:None:`axis`
.
This is equivalent to (but faster than) the following use of :None:None:`ndindex`
and :None:None:`s_`
, which sets each of ii
, jj
, and kk
to a tuple of indices:
Ni, Nk = a.shape[:axis], a.shape[axis+1:] for ii in ndindex(Ni): for kk in ndindex(Nk): f = func1d(arr[ii + s_[:,] + kk]) Nj = f.shape for jj in ndindex(Nj): out[ii + jj + kk] = f[jj]
Equivalently, eliminating the inner loop, this can be expressed as:
Ni, Nk = a.shape[:axis], a.shape[axis+1:] for ii in ndindex(Ni): for kk in ndindex(Nk): out[ii + s_[...,] + kk] = func1d(arr[ii + s_[:,] + kk])
This function should accept 1-D arrays. It is applied to 1-D slices of :None:None:`arr`
along the specified axis.
Axis along which :None:None:`arr`
is sliced.
Input array.
Additional arguments to :None:None:`func1d`
.
Additional named arguments to :None:None:`func1d`
.
The output array. The shape of :None:None:`out`
is identical to the shape of :None:None:`arr`
, except along the :None:None:`axis`
dimension. This axis is removed, and replaced with new dimensions equal to the shape of the return value of :None:None:`func1d`
. So if :None:None:`func1d`
returns a scalar :None:None:`out`
will have one fewer dimensions than :None:None:`arr`
.
Apply a function to 1-D slices along the given axis.
apply_over_axes
Apply a function repeatedly over multiple axes.
>>> def my_func(a): # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... """Average first and last element of a 1-D array"""
... return (a[0] + a[-1]) * 0.5
... b = np.array([[1,2,3], [4,5,6], [7,8,9]]) # doctest: +SKIP
... np.apply_along_axis(my_func, 0, b) # doctest: +SKIP array([4., 5., 6.])
>>> np.apply_along_axis(my_func, 1, b) # doctest: +SKIP array([2., 5., 8.])
For a function that returns a 1D array, the number of dimensions in :None:None:`outarr`
is the same as :None:None:`arr`
.
>>> b = np.array([[8,1,7], [4,3,9], [5,2,6]]) # doctest: +SKIP
... np.apply_along_axis(sorted, 1, b) # doctest: +SKIP array([[1, 7, 8], [3, 4, 9], [2, 5, 6]])
For a function that returns a higher dimensional array, those dimensions are inserted in place of the :None:None:`axis`
dimension.
>>> b = np.array([[1,2,3], [4,5,6], [7,8,9]]) # doctest: +SKIPSee :
... np.apply_along_axis(np.diag, -1, b) # doctest: +SKIP array([[[1, 0, 0], [0, 2, 0], [0, 0, 3]], [[4, 0, 0], [0, 5, 0], [0, 0, 6]], [[7, 0, 0], [0, 8, 0], [0, 0, 9]]])
The following pages refer to to this document either explicitly or contain code examples using this.
dask.array.routines.take
dask.array.routines.apply_over_axes
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them