impy.arrays.bases package

Submodules

impy.arrays.bases.metaarray module

class impy.arrays.bases.metaarray.MetaArray(obj, name: str | None = None, axes: str | None = None, source: str | Path | None = None, metadata: dict[str, Any] | None = None, dtype: DTypeLike = None)[source]

Bases: impy.arrays.axesmixin.AxesMixin, numpy.ndarray

NP_DISPATCH = {<function squeeze>: <function _>, <function take>: <function _>, <function stack>: <function _>, <function concatenate>: <function _>, <function block>: <function _>, <function zeros_like>: <function _>, <function empty_like>: <function _>, <function expand_dims>: <function _>, <function transpose>: <function _>, <function split>: <function _>}
additional_props = ['_source', '_metadata', '_name']
apply_dask(func: Callable, c_axes: str | None = None, drop_axis: Iterable[int] = [], new_axis: Iterable[int] = None, dtype=<class 'numpy.float32'>, out_chunks: tuple[int, ...] = None, args: tuple[Any] = None, kwargs: dict[str, Any] = None) Self[source]

Convert array into dask array and run a batch process in parallel. In many cases batch process in this way is faster than multiprocess module.

Parameters
  • func (callable) – Function to apply.

  • c_axes (str, optional) – Axes to iterate.

  • drop_axis (Iterable[int], optional) – Passed to map_blocks.

  • new_axis (Iterable[int], optional) – Passed to map_blocks.

  • dtype (any that can be converted to np.dtype object, default is np.float32) – Output data type.

  • out_chunks (tuple of int, optional) – Output chunks. This argument is important when the output shape will change.

  • args (tuple, optional) – Arguments that will passed to func.

  • kwargs (dict) – Keyword arguments that will passed to func.

Returns

Processed array.

Return type

MetaArray

argmax_nd() tuple[int, ...][source]

N-dimensional version of argmax.

For instance, if yx-array takes its maximum at (5, 8), this function returns AxesShape(y=5, x=8).

Returns

Argmax of the array.

Return type

AxesShape

classmethod implements(numpy_function)[source]

Add functions to NP_DISPATCH so that numpy functions can be overloaded.

property metadata: dict[str, typing.Any]

Metadata dictionary of the array.

property name: str

Name of the array.

property shape

Tuple of array dimensions.

The shape property is usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with numpy.reshape, one of the new shape dimensions can be -1, in which case its value is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required.

Examples

>>> x = np.array([1, 2, 3, 4])
>>> x.shape
(4,)
>>> y = np.zeros((2, 3, 4))
>>> y.shape
(2, 3, 4)
>>> y.shape = (3, 8)
>>> y
array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])
>>> y.shape = (3, 6)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: total size of new array must be unchanged
>>> np.zeros((4,2))[::2].shape = (-1,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Incompatible shape for in-place modification. Use
`.reshape()` to make a copy with the desired shape.

See also

numpy.reshape

similar function

ndarray.reshape

similar method

sort_axes() Self[source]

Sort image dimensions to ptzcyx-order

Returns

Sorted image

Return type

MetaArray

property source

The source file path.

split(axis=None) DataList[Self][source]

Split n-dimensional image into (n-1)-dimensional images.

Parameters

axis (str or int, optional) – Along which axis the original image will be split, by default “c”

Returns

Separate images

Return type

list of arrays

transpose(axes) Self[source]

change the order of image dimensions. ‘axes’ will also be arranged.

property value: numpy.ndarray

Numpy view of the array.

impy.arrays.bases.overload module

Module contents