Array#
- class gwpy.types.Array(
- value: QuantityLike,
- *,
- unit: UnitBase | str | None = None,
- name: str | None = None,
- epoch: SupportsToGps | None = None,
- channel: Channel | str | None = None,
- dtype: DTypeLike = None,
- copy: bool = True,
- subok: bool = True,
- order: str | None = None,
- ndmin: int = 0,
Bases:
QuantityArray holding data with a unit, and other metadata.
This
Arrayholds the input data and a standard set of metadata properties associated with GW data.- Parameters:
- valuearray_like
Input data array.
- unit
Unit Physical unit of these data.
- epoch
LIGOTimeGPS,float,str GPS epoch associated with these data, any input parsable by
to_gpsis fine- name
str Descriptive title for this array.
- channel
Channel,str Source data stream for these data.
- dtype
dtype Input data type.
- copy
bool Choose to copy the input data to new memory.
- subok
bool Allow passing of sub-classes by the array generator.
- Returns:
- array
Array A new array, with a view of the data, and all associated metadata.
- array
Examples
To create a new
Arrayfrom a list of samples:>>> a = Array([1, 2, 3, 4, 5], 'm/s', name='my data') >>> print(a) Array([ 1., 2., 3., 4., 5.] unit: Unit("m / s"), name: 'my data', epoch: None, channel: None)
Attributes Summary
Instrumental channel associated with these data.
GPS epoch associated with these data.
Name for this data set.
The physical unit of these data.
Methods Summary
abs(**kwargs)Return the absolute value of the data in this
Array.copy([order])Return a copy of the array.
flatten([order])Return a copy of the array collapsed into one dimension.
median([axis])Return the median of the data in this
Array.override_unit(unit[, parse_strict])Reset the unit of these data.
Attributes Documentation
Methods Documentation
- abs(**kwargs) Self | Quantity[source]#
Return the absolute value of the data in this
Array.See also
numpy.absoluteFor details of all available positional and keyword arguments, and for details of the return value.
- copy(order='C')[source]#
Return a copy of the array.
- Parameters:
- order{‘C’, ‘F’, ‘A’, ‘K’}, optional
Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if
ais Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout ofaas closely as possible. (Note that this function andnumpy.copy()are very similar but have different default values for their order= arguments, and this function always passes sub-classes through.)
See also
numpy.copySimilar function with different default behavior
numpy.copyto
Notes
This function is the preferred method for creating an array copy. The function
numpy.copy()is similar, but it defaults to using order ‘K’, and will not pass sub-classes through by default.Examples
>>> import numpy as np >>> x = np.array([[1,2,3],[4,5,6]], order='F')
>>> y = x.copy()
>>> x.fill(0)
>>> x array([[0, 0, 0], [0, 0, 0]])
>>> y array([[1, 2, 3], [4, 5, 6]])
>>> y.flags['C_CONTIGUOUS'] True
For arrays containing Python objects (e.g. dtype=object), the copy is a shallow one. The new array will contain the same object which may lead to surprises if that object can be modified (is mutable):
>>> a = np.array([1, 'm', [2, 3, 4]], dtype=object) >>> b = a.copy() >>> b[2][0] = 10 >>> a array([1, 'm', list([10, 3, 4])], dtype=object)
To ensure all elements within an
objectarray are copied, usecopy.deepcopy:>>> import copy >>> a = np.array([1, 'm', [2, 3, 4]], dtype=object) >>> c = copy.deepcopy(a) >>> c[2][0] = 10 >>> c array([1, 'm', list([10, 3, 4])], dtype=object) >>> a array([1, 'm', list([2, 3, 4])], dtype=object)
- flatten(order: str = 'C') Quantity[source]#
Return a copy of the array collapsed into one dimension.
Any index information is removed as part of the flattening, and the result is returned as a
Quantityarray.- Parameters:
- order{‘C’, ‘F’, ‘A’, ‘K’}
‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if
ais Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flattenain the order the elements occur in memory. The default is ‘C’.
- Returns:
- y
Quantity A copy of the input array, flattened to one dimension.
- y
See also
ravelReturn a flattened array.
flatA 1-D flat iterator over the array.
Examples
>>> a = Array([[1,2], [3,4]], unit='m', name='Test') >>> a.flatten() <Quantity [1., 2., 3., 4.] m>
- median( ) Self | Quantity[source]#
Return the median of the data in this
Array.See also
numpy.medianFor details of all available positional and keyword arguments, and for details of the return value.
- override_unit(
- unit: UnitLike,
- parse_strict: Literal['raise', 'warn', 'silent'] = 'raise',
Reset the unit of these data.
Use of this method is discouraged in favour of
to(), which performs accurate conversions from one unit to another. The method should really only be used when the original unit of the array is plain wrong.- Parameters:
- unit
Unit,str the unit to force onto this array
- parse_strict
str how to handle errors in the unit parsing, default is to raise the underlying exception from
astropy.units
- unit
See also
gwpy.detector.units.parse_unitFor details of unit string parsing.