Skip to main content
`Ctrl`+`K`

# NDArrayShapeMethods

class astropy.utils.shapes.NDArrayShapeMethods

  Bases: `object`

  Mixin class to provide shape-changing methods.

  The class proper is assumed to have some underlying data, which are arrays or array-like structures. It must define a `shape` property, which gives the shape of those data, as well as an `_apply` method that creates a new instance in which a `ndarray` method has been applied to those.

  Furthermore, for consistency with `ndarray`, it is recommended to define a setter for the `shape` property, which, like the `shape` property allows in-place reshaping the internal data (and, unlike the `reshape` method raises an exception if this is not possible).

  This class only provides the shape-changing methods and is meant in particular for `ndarray` subclasses that need to keep track of other arrays. For other classes, `ShapedLikeNDArray` is recommended.

  Attributes Summary

  `T` | Return an instance with the data transposed.

  Methods Summary

  `copy`(*args, **kwargs) | Return an instance containing copies of the internal data.
  `diagonal`(*args, **kwargs) | Return an instance with the specified diagonals.
  `flatten`(*args, **kwargs) | Return a copy with the array collapsed into one dimension.
  `ravel`(*args, **kwargs) | Return an instance with the array collapsed into one dimension.
  `reshape`(*args, **kwargs) | Returns an instance containing the same data with a new shape.
  `squeeze`(*args, **kwargs) | Return an instance with single-dimensional shape entries removed.
  `swapaxes`(*args, **kwargs) | Return an instance with the given axes interchanged.
  `take`(indices[, axis, out, mode]) | Return a new instance formed from the elements at the given indices.
  `transpose`(*args, **kwargs) | Return an instance with the data transposed.

  Attributes Documentation

  T

    Return an instance with the data transposed.

    Parameters are as for `T`. All internal data are views of the data of the original.

  Methods Documentation

  copy(*args, **kwargs)

    Return an instance containing copies of the internal data.

    Parameters are as for `copy()`.

  diagonal(*args, **kwargs)

    Return an instance with the specified diagonals.

    Parameters are as for `diagonal()`. All internal data are views of the data of the original.

  flatten(*args, **kwargs)

    Return a copy with the array collapsed into one dimension.

    Parameters are as for `flatten()`.

  ravel(*args, **kwargs)

    Return an instance with the array collapsed into one dimension.

    Parameters are as for `ravel()`. Note that it is not always possible to unravel an array without copying the data. If you want an error to be raise if the data is copied, you should should assign shape `(-1,)` to the shape attribute.

  reshape(*args, **kwargs)

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

    Parameters are as for `reshape()`. Note that it is not always possible to change the shape of an array without copying the data (see `reshape()` documentation). If you want an error to be raise if the data is copied, you should assign the new shape to the shape attribute (note: this may not be implemented for all classes using `NDArrayShapeMethods`).

  squeeze(*args, **kwargs)

    Return an instance with single-dimensional shape entries removed.

    Parameters are as for `squeeze()`. All internal data are views of the data of the original.

  swapaxes(*args, **kwargs)

    Return an instance with the given axes interchanged.

    Parameters are as for `swapaxes()`: `axis1, axis2`. All internal data are views of the data of the original.

  take(indices, axis=None, out=None, mode='raise')

    Return a new instance formed from the elements at the given indices.

    Parameters are as for `take()`, except that, obviously, no output array can be given.

  transpose(*args, **kwargs)

    Return an instance with the data transposed.

    Parameters are as for `transpose()`. All internal data are views of the data of the original.