NDArrayShapeMethods¶
- class astropy.utils.shapes.NDArrayShapeMethods[source]¶
Bases:
objectMixin 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
shapeproperty, which gives the shape of those data, as well as an_applymethod that creates a new instance in which andarraymethod has been applied to those.Furthermore, for consistency with
ndarray, it is recommended to define a setter for theshapeproperty, which, like theshapeproperty allows in-place reshaping the internal data (and, unlike thereshapemethod raises an exception if this is not possible).This class only provides the shape-changing methods and is meant in particular for
ndarraysubclasses that need to keep track of other arrays. For other classes,ShapedLikeNDArrayis recommended.Attributes Summary
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)[source]¶
Return an instance containing copies of the internal data.
Parameters are as for
copy().
- diagonal(*args, **kwargs)[source]¶
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)[source]¶
Return a copy with the array collapsed into one dimension.
Parameters are as for
flatten().
- ravel(*args, **kwargs)[source]¶
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)[source]¶
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 (seereshape()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 usingNDArrayShapeMethods).
- squeeze(*args, **kwargs)[source]¶
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)[source]¶
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')[source]¶
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)[source]¶
Return an instance with the data transposed.
Parameters are as for
transpose(). All internal data are views of the data of the original.