impy.arrays.bases package

Submodules

impy.arrays.bases.metaarray module

class impy.arrays.bases.metaarray.MetaArray(obj, name: str | None = None, axes: Iterable[Hashable] | 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 _>, <function broadcast_to>: <function _>, <function moveaxis>: <function _>, <function swapaxes>: <function _>}
property T: Self

The transposed array.

Same as self.transpose().

Examples

>>> x = np.array([[1.,2.],[3.,4.]])
>>> x
array([[ 1.,  2.],
       [ 3.,  4.]])
>>> x.T
array([[ 1.,  3.],
       [ 2.,  4.]])
>>> x = np.array([1.,2.,3.,4.])
>>> x
array([ 1.,  2.,  3.,  4.])
>>> x.T
array([ 1.,  2.,  3.,  4.])

See also

transpose

additional_props = ['_source', '_metadata', '_name']
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

broadcast_to(shape: tuple[int, ...], axes: AxesLike | None = None) Self[source]

Broadcast array to specified shape and axes.

Parameters
  • shape (shape-like) – Shape of output array.

  • axes (AxesLike, optional) – Axes of output array. If given, it must match the dimensionality of input shape.

Returns

Broadcasted array.

Return type

MetaArray

classmethod implements(numpy_function)[source]

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

isel(indexer=None, /, **kwargs: dict[str, Any]) Self[source]
property metadata: dict[str, Any]

Metadata dictionary of the array.

property name: str

Name of the array.

reshape(shape, order='C')[source]

Returns an array containing the same data with a new shape.

Refer to numpy.reshape for full documentation.

See also

numpy.reshape

equivalent function

Notes

Unlike the free function numpy.reshape, this method on ndarray allows the elements of the shape parameter to be passed in as separate arguments. For example, a.reshape(10, 11) is equivalent to a.reshape((10, 11)).

sel(indexer=None, /, **kwargs: dict[str, Any]) Self[source]

.

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.

Warning

Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the preferred approach.

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.shape

Equivalent getter function.

numpy.reshape

Function similar to setting shape.

ndarray.reshape

Method similar to setting shape.

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.

class impy.arrays.bases.metaarray.NotMe[source]

Bases: object

impy.arrays.bases.overload module

impy.arrays.bases.overload.np_normalize_axis_tuple(axis, ndim, argname=None, allow_duplicate=False)[source]

Module contents