ShapedLikeNDArray¶
-
class
astropy.utils.misc.
ShapedLikeNDArray
[source]¶ 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 andarray
method has been applied to those.Furthermore, for consistency with
ndarray
, it is recommended to define a setter for theshape
property, which, like theshape
property allows in-place reshaping the internal data (and, unlike thereshape
method raises an exception if this is not possible).This class also defines default implementations for
ndim
andsize
properties, calculating those from theshape
. These can be overridden by subclasses if there are faster ways to obtain those numbers.Attributes Summary
Return an instance with the data transposed.
The number of dimensions of the instance and underlying arrays.
The shape of the instance and underlying arrays.
The size of the object, as calculated from its shape.
Methods Summary
copy
(self, \*args, \*\*kwargs)Return an instance containing copies of the internal data.
diagonal
(self, \*args, \*\*kwargs)Return an instance with the specified diagonals.
flatten
(self, \*args, \*\*kwargs)Return a copy with the array collapsed into one dimension.
ravel
(self, \*args, \*\*kwargs)Return an instance with the array collapsed into one dimension.
reshape
(self, \*args, \*\*kwargs)Returns an instance containing the same data with a new shape.
squeeze
(self, \*args, \*\*kwargs)Return an instance with single-dimensional shape entries removed
swapaxes
(self, \*args, \*\*kwargs)Return an instance with the given axes interchanged.
take
(self, indices[, axis, mode])Return a new instance formed from the elements at the given indices.
transpose
(self, \*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.
-
isscalar
¶
-
ndim
¶ The number of dimensions of the instance and underlying arrays.
-
shape
¶ The shape of the instance and underlying arrays.
-
size
¶ The size of the object, as calculated from its shape.
Methods Documentation
-
copy
(self, *args, **kwargs)[source]¶ Return an instance containing copies of the internal data.
Parameters are as for
copy()
.
-
diagonal
(self, *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
(self, *args, **kwargs)[source]¶ Return a copy with the array collapsed into one dimension.
Parameters are as for
flatten()
.
-
ravel
(self, *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
(self, *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 usingShapedLikeNDArray
).
-
squeeze
(self, *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
(self, *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
(self, indices, axis=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
(self, *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.
-