pynn_brainscales.brainscales2.standardmodels.cells.Quantity
-
class
pynn_brainscales.brainscales2.standardmodels.cells.
Quantity
(data, units='', dtype=None, copy=True) Bases:
numpy.ndarray
-
__init__
() Initialize self. See help(type(self)) for accurate signature.
Methods
argmax
([axis, out, keepdims])Return indices of the maximum values along the given axis.
argmin
([axis, out, keepdims])Return indices of the minimum values along the given axis.
argsort
([axis, kind, order])Returns the indices that would sort this array.
astype
(dtype[, order, casting, subok, copy])Copy of the array, cast to a specified type.
clip
([min, max, out])Return an array whose values are limited to
[min, 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.
fill
(value)Fill the array with a scalar value.
max
([axis, out, keepdims, initial, where])Return the maximum along a given axis.
mean
([axis, dtype, out, keepdims, where])Returns the average of the array elements along given axis.
min
([axis, out, keepdims, initial, where])Return the minimum along a given axis.
nanargmax
([axis, out])Return the indices of the maximum values in the specified axis ignoring NaNs.
nanargmin
([axis, out])Return the indices of the minimum values in the specified axis ignoring NaNs.
nanmax
([axis, out])Return the maximum of an array or maximum along an axis, ignoring any NaNs.
nanmean
([axis, dtype, out])Compute the arithmetic mean along the specified axis, ignoring NaNs.
nanmin
([axis, out])Return minimum of an array or minimum along an axis, ignoring any NaNs.
nanstd
([axis, dtype, out, ddof])Compute the standard deviation along the specified axis, while ignoring NaNs.
nansum
([axis, dtype, out])Return the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.
nonzero
()Return the indices of the elements that are non-zero.
prod
([axis, dtype, out, keepdims, initial, …])Return the product of the array elements over the given axis
ptp
([axis, out, keepdims])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.rescale
([units])Return a copy of the quantity converted to the specified units.
Return a copy of the quantity converted to the preferred units and scale.
round
([decimals, out])Return a with each element rounded to the given number of decimals.
searchsorted
(v[, side, sorter])Find indices where elements of v should be inserted in a to maintain order.
squeeze
([axis])Remove axes of length one from a.
std
([axis, dtype, out, ddof, keepdims, where])Returns the standard deviation of the array elements along given axis.
sum
([axis, dtype, out, keepdims, initial, where])Return the sum of the array elements over the given axis.
tolist
()Return the array as an
a.ndim
-levels deep nested list of Python scalars.trace
([offset, axis1, axis2, dtype, out])Return the sum along diagonals of the array.
var
([axis, dtype, out, ddof, keepdims, where])Returns the variance of the array elements, along given axis.
Attributes
The imaginary part of the array.
The real part of the array.
-
argmax
(axis=None, out=None, *, keepdims=False) Return indices of the maximum values along the given axis.
Refer to numpy.argmax for full documentation.
numpy.argmax : equivalent function
-
argmin
(axis=None, out=None, *, keepdims=False) Return indices of the minimum values along the given axis.
Refer to numpy.argmin for detailed documentation.
numpy.argmin : equivalent function
-
argsort
(axis=- 1, kind=None, order=None) Returns the indices that would sort this array.
Refer to numpy.argsort for full documentation.
numpy.argsort : equivalent function
-
astype
(dtype, order='K', casting='unsafe', subok=True, copy=True) Copy of the array, cast to a specified type.
- dtypestr or dtype
Typecode or data-type to which the array is cast.
- order{‘C’, ‘F’, ‘A’, ‘K’}, optional
Controls the memory layout order of the result. ‘C’ means C order, ‘F’ means Fortran order, ‘A’ means ‘F’ order if all the arrays are Fortran contiguous, ‘C’ order otherwise, and ‘K’ means as close to the order the array elements appear in memory as possible. Default is ‘K’.
- casting{‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional
Controls what kind of data casting may occur. Defaults to ‘unsafe’ for backwards compatibility.
‘no’ means the data types should not be cast at all.
‘equiv’ means only byte-order changes are allowed.
‘safe’ means only casts which can preserve values are allowed.
‘same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.
‘unsafe’ means any data conversions may be done.
- subokbool, optional
If True, then sub-classes will be passed-through (default), otherwise the returned array will be forced to be a base-class array.
- copybool, optional
By default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy.
- arr_tndarray
Unless copy is False and the other conditions for returning the input array are satisfied (see description for copy input parameter), arr_t is a new array of the same shape as the input array, with dtype, order given by dtype, order.
Changed in version 1.17.0: Casting between a simple data type and a structured one is possible only for “unsafe” casting. Casting to multiple fields is allowed, but casting from multiple fields is not.
Changed in version 1.9.0: Casting from numeric to string types in ‘safe’ casting mode requires that the string dtype length is long enough to store the max integer/float value converted.
- ComplexWarning
When casting from complex to float or int. To avoid this, one should use
a.real.astype(t)
.
>>> x = np.array([1, 2, 2.5]) >>> x array([1. , 2. , 2.5])
>>> x.astype(int) array([1, 2, 2])
Scalars are returned as scalar Quantity arrays.
-
clip
(min=None, max=None, out=None, **kwargs) Return an array whose values are limited to
[min, max]
. One of max or min must be given.Refer to numpy.clip for full documentation.
numpy.clip : equivalent function
-
cumprod
(axis=None, dtype=None, out=None) Return the cumulative product of the elements along the given axis.
Refer to numpy.cumprod for full documentation.
numpy.cumprod : equivalent function
-
cumsum
(axis=None, dtype=None, out=None) Return the cumulative sum of the elements along the given axis.
Refer to numpy.cumsum for full documentation.
numpy.cumsum : equivalent function
-
property
dimensionality
-
fill
(value) Fill the array with a scalar value.
- valuescalar
All elements of a will be assigned this value.
>>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
-
property
imag
The imaginary part of the array.
>>> x = np.sqrt([1+0j, 0+1j]) >>> x.imag array([ 0. , 0.70710678]) >>> x.imag.dtype dtype('float64')
-
property
magnitude
-
max
(axis=None, out=None, keepdims=False, initial=<no value>, where=True) Return the maximum along a given axis.
Refer to numpy.amax for full documentation.
numpy.amax : equivalent function
-
mean
(axis=None, dtype=None, out=None, keepdims=False, *, where=True) Returns the average of the array elements along given axis.
Refer to numpy.mean for full documentation.
numpy.mean : equivalent function
-
min
(axis=None, out=None, keepdims=False, initial=<no value>, where=True) Return the minimum along a given axis.
Refer to numpy.amin for full documentation.
numpy.amin : equivalent function
-
nanargmax
(axis=None, out=None) Return the indices of the maximum values in the specified axis ignoring NaNs. For all-NaN slices
ValueError
is raised. Warning: the results cannot be trusted if a slice contains only NaNs and -Infs.- aarray_like
Input data.
- axisint, optional
Axis along which to operate. By default flattened input is used.
- outarray, optional
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
New in version 1.22.0.
- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.
New in version 1.22.0.
- index_arrayndarray
An array of indices or a single index value.
argmax, nanargmin
>>> a = np.array([[np.nan, 4], [2, 3]]) >>> np.argmax(a) 0 >>> np.nanargmax(a) 1 >>> np.nanargmax(a, axis=0) array([1, 0]) >>> np.nanargmax(a, axis=1) array([1, 1])
-
nanargmin
(axis=None, out=None) Return the indices of the minimum values in the specified axis ignoring NaNs. For all-NaN slices
ValueError
is raised. Warning: the results cannot be trusted if a slice contains only NaNs and Infs.- aarray_like
Input data.
- axisint, optional
Axis along which to operate. By default flattened input is used.
- outarray, optional
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
New in version 1.22.0.
- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.
New in version 1.22.0.
- index_arrayndarray
An array of indices or a single index value.
argmin, nanargmax
>>> a = np.array([[np.nan, 4], [2, 3]]) >>> np.argmin(a) 0 >>> np.nanargmin(a) 2 >>> np.nanargmin(a, axis=0) array([1, 1]) >>> np.nanargmin(a, axis=1) array([1, 0])
-
nanmax
(axis=None, out=None) Return the maximum of an array or maximum along an axis, ignoring any NaNs. When all-NaN slices are encountered a
RuntimeWarning
is raised and NaN is returned for that slice.- aarray_like
Array containing numbers whose maximum is desired. If a is not an array, a conversion is attempted.
- axis{int, tuple of int, None}, optional
Axis or axes along which the maximum is computed. The default is to compute the maximum of the flattened array.
- outndarray, optional
Alternate output array in which to place the result. The default is
None
; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See ufuncs-output-type for more details.New in version 1.8.0.
- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the max method of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
New in version 1.8.0.
- initialscalar, optional
The minimum value of an output element. Must be present to allow computation on empty slice. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- wherearray_like of bool, optional
Elements to compare for the maximum. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- nanmaxndarray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, an ndarray scalar is returned. The same dtype as a is returned.
- nanmin :
The minimum value of an array along a given axis, ignoring any NaNs.
- amax :
The maximum value of an array along a given axis, propagating any NaNs.
- fmax :
Element-wise maximum of two arrays, ignoring any NaNs.
- maximum :
Element-wise maximum of two arrays, propagating any NaNs.
- isnan :
Shows which elements are Not a Number (NaN).
- isfinite:
Shows which elements are neither NaN nor infinity.
amin, fmin, minimum
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number.
If the input has a integer type the function is equivalent to np.max.
>>> a = np.array([[1, 2], [3, np.nan]]) >>> np.nanmax(a) 3.0 >>> np.nanmax(a, axis=0) array([3., 2.]) >>> np.nanmax(a, axis=1) array([2., 3.])
When positive infinity and negative infinity are present:
>>> np.nanmax([1, 2, np.nan, np.NINF]) 2.0 >>> np.nanmax([1, 2, np.nan, np.inf]) inf
-
nanmean
(axis=None, dtype=None, out=None) Compute the arithmetic mean along the specified axis, ignoring NaNs.
Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
For all-NaN slices, NaN is returned and a RuntimeWarning is raised.
New in version 1.8.0.
- aarray_like
Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted.
- axis{int, tuple of int, None}, optional
Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.
- dtypedata-type, optional
Type to use in computing the mean. For integer inputs, the default is float64; for inexact inputs, it is the same as the input dtype.
- outndarray, optional
Alternate output array in which to place the result. The default is
None
; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See ufuncs-output-type for more details.- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
- wherearray_like of bool, optional
Elements to include in the mean. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- mndarray, see dtype parameter above
If out=None, returns a new array containing the mean values, otherwise a reference to the output array is returned. Nan is returned for slices that contain only NaNs.
average : Weighted average mean : Arithmetic mean taken while not ignoring NaNs var, nanvar
The arithmetic mean is the sum of the non-NaN elements along the axis divided by the number of non-NaN elements.
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32. Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue.
>>> a = np.array([[1, np.nan], [3, 4]]) >>> np.nanmean(a) 2.6666666666666665 >>> np.nanmean(a, axis=0) array([2., 4.]) >>> np.nanmean(a, axis=1) array([1., 3.5]) # may vary
-
nanmin
(axis=None, out=None) Return minimum of an array or minimum along an axis, ignoring any NaNs. When all-NaN slices are encountered a
RuntimeWarning
is raised and Nan is returned for that slice.- aarray_like
Array containing numbers whose minimum is desired. If a is not an array, a conversion is attempted.
- axis{int, tuple of int, None}, optional
Axis or axes along which the minimum is computed. The default is to compute the minimum of the flattened array.
- outndarray, optional
Alternate output array in which to place the result. The default is
None
; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See ufuncs-output-type for more details.New in version 1.8.0.
- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the min method of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
New in version 1.8.0.
- initialscalar, optional
The maximum value of an output element. Must be present to allow computation on empty slice. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- wherearray_like of bool, optional
Elements to compare for the minimum. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- nanminndarray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, an ndarray scalar is returned. The same dtype as a is returned.
- nanmax :
The maximum value of an array along a given axis, ignoring any NaNs.
- amin :
The minimum value of an array along a given axis, propagating any NaNs.
- fmin :
Element-wise minimum of two arrays, ignoring any NaNs.
- minimum :
Element-wise minimum of two arrays, propagating any NaNs.
- isnan :
Shows which elements are Not a Number (NaN).
- isfinite:
Shows which elements are neither NaN nor infinity.
amax, fmax, maximum
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number.
If the input has a integer type the function is equivalent to np.min.
>>> a = np.array([[1, 2], [3, np.nan]]) >>> np.nanmin(a) 1.0 >>> np.nanmin(a, axis=0) array([1., 2.]) >>> np.nanmin(a, axis=1) array([1., 3.])
When positive infinity and negative infinity are present:
>>> np.nanmin([1, 2, np.nan, np.inf]) 1.0 >>> np.nanmin([1, 2, np.nan, np.NINF]) -inf
-
nanstd
(axis=None, dtype=None, out=None, ddof=0) Compute the standard deviation along the specified axis, while ignoring NaNs.
Returns the standard deviation, a measure of the spread of a distribution, of the non-NaN array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
For all-NaN slices or slices with zero degrees of freedom, NaN is returned and a RuntimeWarning is raised.
New in version 1.8.0.
- aarray_like
Calculate the standard deviation of the non-NaN values.
- axis{int, tuple of int, None}, optional
Axis or axes along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array.
- dtypedtype, optional
Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.
- outndarray, optional
Alternative output array in which to place the result. It must have the same shape as the expected output but the type (of the calculated values) will be cast if necessary.
- ddofint, optional
Means Delta Degrees of Freedom. The divisor used in calculations is
N - ddof
, whereN
represents the number of non-NaN elements. By default ddof is zero.- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If this value is anything but the default it is passed through as-is to the relevant functions of the sub-classes. If these functions do not have a keepdims kwarg, a RuntimeError will be raised.
- wherearray_like of bool, optional
Elements to include in the standard deviation. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- standard_deviationndarray, see dtype parameter above.
If out is None, return a new array containing the standard deviation, otherwise return a reference to the output array. If ddof is >= the number of non-NaN elements in a slice or the slice contains only NaNs, then the result for that slice is NaN.
var, mean, std nanvar, nanmean ufuncs-output-type
The standard deviation is the square root of the average of the squared deviations from the mean:
std = sqrt(mean(abs(x - x.mean())**2))
.The average squared deviation is normally calculated as
x.sum() / N
, whereN = len(x)
. If, however, ddof is specified, the divisorN - ddof
is used instead. In standard statistical practice,ddof=1
provides an unbiased estimator of the variance of the infinite population.ddof=0
provides a maximum likelihood estimate of the variance for normally distributed variables. The standard deviation computed in this function is the square root of the estimated variance, so even withddof=1
, it will not be an unbiased estimate of the standard deviation per se.Note that, for complex numbers, std takes the absolute value before squaring, so that the result is always real and nonnegative.
For floating-point input, the std is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue.
>>> a = np.array([[1, np.nan], [3, 4]]) >>> np.nanstd(a) 1.247219128924647 >>> np.nanstd(a, axis=0) array([1., 0.]) >>> np.nanstd(a, axis=1) array([0., 0.5]) # may vary
-
nansum
(axis=None, dtype=None, out=None) Return the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.
In NumPy versions <= 1.9.0 Nan is returned for slices that are all-NaN or empty. In later versions zero is returned.
- aarray_like
Array containing numbers whose sum is desired. If a is not an array, a conversion is attempted.
- axis{int, tuple of int, None}, optional
Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array.
- dtypedata-type, optional
The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the platform (u)intp. In that case, the default will be either (u)int32 or (u)int64 depending on whether the platform is 32 or 64 bits. For inexact inputs, dtype must be inexact.
New in version 1.8.0.
- outndarray, optional
Alternate output array in which to place the result. The default is
None
. If provided, it must have the same shape as the expected output, but the type will be cast if necessary. See ufuncs-output-type for more details. The casting of NaN to integer can yield unexpected results.New in version 1.8.0.
- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
New in version 1.8.0.
- initialscalar, optional
Starting value for the sum. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- wherearray_like of bool, optional
Elements to include in the sum. See ~numpy.ufunc.reduce for details.
New in version 1.22.0.
- nansumndarray.
A new array holding the result is returned unless out is specified, in which it is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.
numpy.sum : Sum across array propagating NaNs. isnan : Show which elements are NaN. isfinite : Show which elements are not NaN or +/-inf.
If both positive and negative infinity are present, the sum will be Not A Number (NaN).
>>> np.nansum(1) 1 >>> np.nansum([1]) 1 >>> np.nansum([1, np.nan]) 1.0 >>> a = np.array([[1, 1], [1, np.nan]]) >>> np.nansum(a) 3.0 >>> np.nansum(a, axis=0) array([2., 1.]) >>> np.nansum([1, np.nan, np.inf]) inf >>> np.nansum([1, np.nan, np.NINF]) -inf >>> from numpy.testing import suppress_warnings >>> with suppress_warnings() as sup: ... sup.filter(RuntimeWarning) ... np.nansum([1, np.nan, np.inf, -np.inf]) # both +/- infinity present nan
-
nonzero
() Return the indices of the elements that are non-zero.
Refer to numpy.nonzero for full documentation.
numpy.nonzero : equivalent function
-
prod
(axis=None, dtype=None, out=None, keepdims=False, initial=1, where=True) Return the product of the array elements over the given axis
Refer to numpy.prod for full documentation.
numpy.prod : equivalent function
-
ptp
(axis=None, out=None, keepdims=False) Peak to peak (maximum - minimum) value along a given axis.
Refer to numpy.ptp for full documentation.
numpy.ptp : equivalent function
-
put
(indices, values, mode='raise') Set
a.flat[n] = values[n]
for all n in indices.Refer to numpy.put for full documentation.
numpy.put : equivalent function
performs the equivalent of ndarray.put() but enforces units values - must be an Quantity with the same units as self
-
property
real
The real part of the array.
>>> x = np.sqrt([1+0j, 0+1j]) >>> x.real array([ 1. , 0.70710678]) >>> x.real.dtype dtype('float64')
numpy.real : equivalent function
-
rescale
(units=None) Return a copy of the quantity converted to the specified units. If units is None, an attempt will be made to rescale the quantity to preferred units (see rescale_preferred).
-
rescale_preferred
() Return a copy of the quantity converted to the preferred units and scale. These will be identified from among the compatible units specified in the list PREFERRED in this module. For example, a voltage quantity might be converted to mV:
` import quantities as pq pq.quantity.PREFERRED = [pq.mV, pq.pA] old = 3.1415 * pq.V new = old.rescale_preferred() # `new` will be 3141.5 mV. `
-
round
(decimals=0, out=None) Return a with each element rounded to the given number of decimals.
Refer to numpy.around for full documentation.
numpy.around : equivalent function
-
searchsorted
(v, side='left', sorter=None) Find indices where elements of v should be inserted in a to maintain order.
For full documentation, see numpy.searchsorted
numpy.searchsorted : equivalent function
-
property
simplified
-
squeeze
(axis=None) Remove axes of length one from a.
Refer to numpy.squeeze for full documentation.
numpy.squeeze : equivalent function
-
std
(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True) Returns the standard deviation of the array elements along given axis.
Refer to numpy.std for full documentation.
numpy.std : equivalent function
-
sum
(axis=None, dtype=None, out=None, keepdims=False, initial=0, where=True) Return the sum of the array elements over the given axis.
Refer to numpy.sum for full documentation.
numpy.sum : equivalent function
-
tolist
() Return the array as an
a.ndim
-levels deep nested list of Python scalars.Return a copy of the array data as a (nested) Python list. Data items are converted to the nearest compatible builtin Python type, via the ~numpy.ndarray.item function.
If
a.ndim
is 0, then since the depth of the nested list is 0, it will not be a list at all, but a simple Python scalar.none
- yobject, or list of object, or list of list of object, or …
The possibly nested list of array elements.
The array may be recreated via
a = np.array(a.tolist())
, although this may sometimes lose precision.For a 1D array,
a.tolist()
is almost the same aslist(a)
, except thattolist
changes numpy scalars to Python scalars:>>> a = np.uint32([1, 2]) >>> a_list = list(a) >>> a_list [1, 2] >>> type(a_list[0]) <class 'numpy.uint32'> >>> a_tolist = a.tolist() >>> a_tolist [1, 2] >>> type(a_tolist[0]) <class 'int'>
Additionally, for a 2D array,
tolist
applies recursively:>>> a = np.array([[1, 2], [3, 4]]) >>> list(a) [array([1, 2]), array([3, 4])] >>> a.tolist() [[1, 2], [3, 4]]
The base case for this recursion is a 0D array:
>>> a = np.array(1) >>> list(a) Traceback (most recent call last): ... TypeError: iteration over a 0-d array >>> a.tolist() 1
-
trace
(offset=0, axis1=0, axis2=1, dtype=None, out=None) Return the sum along diagonals of the array.
Refer to numpy.trace for full documentation.
numpy.trace : equivalent function
-
property
units
-
var
(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True) Returns the variance of the array elements, along given axis.
Refer to numpy.var for full documentation.
numpy.var : equivalent function
-