Bases: numpy.ndarray
A Quantity represents a number with some associated unit.
Parameters: | value : number, ndarray, Quantity object, or sequence of Quantity objects. unit : UnitBase instance, str dtype : ~numpy.dtype, optional
copy : bool, optional
order : {‘C’, ‘F’, ‘A’}, optional subok : bool, optional ndmin : int, optional
|
---|---|
Raises: | TypeError
TypeError
|
Attributes Summary
cgs | Returns a copy of the current Quantity instance with CGS units. |
equivalencies | A list of equivalencies that will be applied by default during unit conversions. |
flat | A 1-D iterator over the Quantity array. |
isscalar | True if the value of this quantity is a scalar, or False if it is an array-like object. |
si | Returns a copy of the current Quantity instance with SI units. |
unit | A UnitBase object representing the unit of this quantity. |
value | The numerical value of this quantity. |
Methods Summary
all([axis, out]) | Returns True if all elements evaluate to True. |
any([axis, out]) | Returns True if any of the elements of a evaluate to True. |
argmax([axis, out]) | Return indices of the maximum values along the given axis. |
argmin([axis, out]) | Return indices of the minimum values along the given axis of a. |
argsort([axis, kind, order]) | Returns the indices that would sort this array. |
choose(choices[, out, mode]) | Use an index array to construct a new array from a set of choices. |
clip(a_min, a_max[, out]) | Return an array whose values are limited to [a_min, a_max]. |
cumprod([axis, dtype, out]) | Return the cumulative product of the elements along the given axis. |
cumsum([axis, dtype, out]) | Return the cumulative sum of the elements along the given axis. |
decompose([bases]) | Generates a new Quantity with the units decomposed. |
diff([n, axis]) | |
dot(b[, out]) | Dot product of two arrays. |
dump(file) | Dump a pickle of the array to the specified file. |
dumps() | Returns the pickle of the array as a string. |
ediff1d([to_end, to_begin]) | |
fill(value) | Fill the array with a scalar value. |
item(*args) | Copy an element of an array to a standard Python scalar and return it. |
itemset(*args) | Insert scalar into an array (scalar is cast to array’s dtype, if possible) There must be at least 1 argument, and define the last argument as item. |
list() | |
max([axis, out]) | Return the maximum along a given axis. |
mean([axis, dtype, out]) | Returns the average of the array elements along given axis. |
min([axis, out]) | Return the minimum along a given axis. |
nansum([axis]) | |
prod([axis, dtype, out]) | Return the product of the array elements over the given axis Refer to numpy.prod for full documentation. |
ptp([axis, out]) | Peak to peak (maximum - minimum) value along a given axis. |
put(indices, values[, mode]) | Set a.flat[n] = values[n] for all n in indices. |
searchsorted(v[, side, sorter]) | Find indices where elements of v should be inserted in a to maintain order. |
std([axis, dtype, out, ddof]) | Returns the standard deviation of the array elements along given axis. |
sum([axis, dtype, out]) | Return the sum of the array elements over the given axis. |
to(unit[, equivalencies]) | Returns a new Quantity object with the specified units. |
tofile(fid[, sep, format]) | Write array to a file as text or binary (default). |
tostring([order]) | Construct a Python string containing the raw data bytes in the array. |
trace([offset, axis1, axis2, dtype, out]) | Return the sum along diagonals of the array. |
var([axis, dtype, out, ddof]) | Returns the variance of the array elements, along given axis. |
Attributes Documentation
Returns a copy of the current Quantity instance with CGS units. The value of the resulting object will be scaled.
A list of equivalencies that will be applied by default during unit conversions.
A 1-D iterator over the Quantity array.
This returns a QuantityIterator instance, which behaves the same as the flatiter instance returned by flat, and is similar to, but not a subclass of, Python’s built-in iterator object.
True if the value of this quantity is a scalar, or False if it is an array-like object.
Note
This is subtly different from numpy.isscalar in that numpy.isscalar returns False for a zero-dimensional array (e.g. np.array(1)), while this is True for quantities, since quantities cannot represent true numpy scalars.
Returns a copy of the current Quantity instance with SI units. The value of the resulting object will be scaled.
The numerical value of this quantity.
Methods Documentation
Returns True if all elements evaluate to True.
Refer to numpy.all for full documentation.
See also
Returns True if any of the elements of a evaluate to True.
Refer to numpy.any for full documentation.
See also
Return indices of the maximum values along the given axis.
Refer to numpy.argmax for full documentation.
See also
Return indices of the minimum values along the given axis of a.
Refer to numpy.argmin for detailed documentation.
See also
Returns the indices that would sort this array.
Refer to numpy.argsort for full documentation.
See also
Use an index array to construct a new array from a set of choices.
Refer to numpy.choose for full documentation.
See also
Return an array whose values are limited to [a_min, a_max].
Refer to numpy.clip for full documentation.
See also
Return the cumulative product of the elements along the given axis.
Refer to numpy.cumprod for full documentation.
See also
Return the cumulative sum of the elements along the given axis.
Refer to numpy.cumsum for full documentation.
See also
Generates a new Quantity with the units decomposed. Decomposed units have only irreducible units in them (see astropy.units.UnitBase.decompose).
Parameters: | bases : sequence of UnitBase, optional
|
---|---|
Returns: | newq : Quantity
|
Dot product of two arrays.
Refer to numpy.dot for full documentation.
See also
Examples
>>> a = np.eye(2)
>>> b = np.ones((2, 2)) * 2
>>> a.dot(b)
array([[ 2., 2.],
[ 2., 2.]])
This array method can be conveniently chained:
>>> a.dot(b).dot(b)
array([[ 8., 8.],
[ 8., 8.]])
Dump a pickle of the array to the specified file. The array can be read back with pickle.load or numpy.load.
Parameters: | file : str
|
---|
Returns the pickle of the array as a string. pickle.loads or numpy.loads will convert the string back to an array.
Parameters: | None |
---|
Fill the array with a scalar value.
Parameters: | value : scalar
|
---|
Examples
>>> a = np.array([1, 2])
>>> a.fill(0)
>>> a
array([0, 0])
>>> a = np.empty(2)
>>> a.fill(1)
>>> a
array([ 1., 1.])
Copy an element of an array to a standard Python scalar and return it.
Parameters: | *args : Arguments (variable number and type)
|
---|---|
Returns: | z : Standard Python scalar object
|
Notes
When the data type of a is longdouble or clongdouble, item() returns a scalar array object because there is no available Python scalar that would not lose information. Void arrays return a buffer object for item(), unless fields are defined, in which case a tuple is returned.
item is very similar to a[args], except, instead of an array scalar, a standard Python scalar is returned. This can be useful for speeding up access to elements of the array and doing arithmetic on elements of the array using Python’s optimized math.
Examples
>>> x = np.random.randint(9, size=(3, 3))
>>> x
array([[3, 1, 7],
[2, 8, 3],
[8, 5, 3]])
>>> x.item(3)
2
>>> x.item(7)
5
>>> x.item((0, 1))
1
>>> x.item((2, 2))
3
Insert scalar into an array (scalar is cast to array’s dtype, if possible)
There must be at least 1 argument, and define the last argument as item. Then, a.itemset(*args) is equivalent to but faster than a[args] = item. The item should be a scalar value and args must select a single item in the array a.
Parameters: | *args : Arguments
|
---|
Notes
Compared to indexing syntax, itemset provides some speed increase for placing a scalar into a particular location in an ndarray, if you must do this. However, generally this is discouraged: among other problems, it complicates the appearance of the code. Also, when using itemset (and item) inside a loop, be sure to assign the methods to a local variable to avoid the attribute look-up at each loop iteration.
Examples
>>> x = np.random.randint(9, size=(3, 3))
>>> x
array([[3, 1, 7],
[2, 8, 3],
[8, 5, 3]])
>>> x.itemset(4, 0)
>>> x.itemset((2, 2), 9)
>>> x
array([[3, 1, 7],
[2, 0, 3],
[8, 5, 9]])
Return the maximum along a given axis.
Refer to numpy.amax for full documentation.
See also
Returns the average of the array elements along given axis.
Refer to numpy.mean for full documentation.
See also
Return the minimum along a given axis.
Refer to numpy.amin for full documentation.
See also
Return the product of the array elements over the given axis
Refer to numpy.prod for full documentation.
See also
Peak to peak (maximum - minimum) value along a given axis.
Refer to numpy.ptp for full documentation.
See also
Set a.flat[n] = values[n] for all n in indices.
Refer to numpy.put for full documentation.
See also
Find indices where elements of v should be inserted in a to maintain order.
For full documentation, see numpy.searchsorted
See also
Returns the standard deviation of the array elements along given axis.
Refer to numpy.std for full documentation.
See also
Return the sum of the array elements over the given axis.
Refer to numpy.sum for full documentation.
See also
Returns a new Quantity object with the specified units.
Parameters: | unit : UnitBase instance, str equivalencies : list of equivalence pairs, optional
|
---|
Write array to a file as text or binary (default).
Data is always written in ‘C’ order, independent of the order of a. The data produced by this method can be recovered using the function fromfile().
Parameters: | fid : file or str
sep : str
format : str
|
---|
Notes
This is a convenience function for quick storage of array data. Information on endianness and precision is lost, so this method is not a good choice for files intended to archive data or transport data between machines with different endianness. Some of these problems can be overcome by outputting the data as text files, at the expense of speed and file size.
Construct a Python string containing the raw data bytes in the array.
Constructs a Python string showing a copy of the raw contents of data memory. The string can be produced in either ‘C’ or ‘Fortran’, or ‘Any’ order (the default is ‘C’-order). ‘Any’ order means C-order unless the F_CONTIGUOUS flag in the array is set, in which case it means ‘Fortran’ order.
Parameters: | order : {‘C’, ‘F’, None}, optional
|
---|---|
Returns: | s : str
|
Examples
>>> x = np.array([[0, 1], [2, 3]])
>>> x.tostring()
'\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
>>> x.tostring('C') == x.tostring()
True
>>> x.tostring('F')
'\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'
Return the sum along diagonals of the array.
Refer to numpy.trace for full documentation.
See also
Returns the variance of the array elements, along given axis.
Refer to numpy.var for full documentation.
See also