rwskit.numpy
Numpy utilities.
Attributes
The valid values for the |
Functions
|
Return a dtype that can be used to represent an arbitrary object. |
|
Checks if a numpy array is a structured array or not. |
|
An array is complete if all its numeric values are finite and all other |
|
Return only the rows whose values are finite and not |
|
Group an |
Module Contents
- rwskit.numpy.CompleteCheckType[source]
The valid values for the
check_typeparameter ofis_complete().
- rwskit.numpy.get_dtype(obj: Any | None) numpy.dtype | None[source]
Return a dtype that can be used to represent an arbitrary object.
For objects that are already numpy arrays or scalars, the dtype from that object is returned. For other python objects, a set of heuristics are used. If the object is iterable, the method will try to determine the type of object
If the dtype can’t be determined, either because the input object was
None, or it is a collection that does not contain any non-null values, then the method will returnNone.- Parameters:
obj (Any) – An object.
- Returns:
A dtype that can be used to represent an arbitrary object, or
Noneif the input object isNone.- Return type:
numpy.dtype, optional
- rwskit.numpy.is_structured(array: numpy.ndarray) bool[source]
Checks if a numpy array is a structured array or not.
- Parameters:
array (np.ndarray) – The array to check.
- Returns:
Trueif the array is a structured array,Falseotherwise.- Return type:
bool
- rwskit.numpy.is_complete(array: numpy.ndarray, check_type: CompleteCheckType = 'finite') bool[source]
An array is complete if all its numeric values are finite and all other values are not
None.Note
For arrays with
dtype=np.object_, the method only checks to make sure no value in the array isNone.- Parameters:
check_type ({"finite", "nan"}) –
Determines how completeness is defined.
- nan
Requires that no values are
np.NaNorNone.- finite
In addition to the criteria for
nanall values must also be finite (i.e., notnp.infor-np.inf).
array (np.ndarray) – The array to check.
- Returns:
Trueif the array is complete,Falseotherwise.- Return type:
bool
- rwskit.numpy.finite_cases(array: numpy.ndarray) numpy.ndarray[source]
Return only the rows whose values are finite and not
None.- Parameters:
array (np.ndarray) – The input array with possibly invalid values.
- Returns:
An array with only non-null finite values.
- Return type:
np.ndarray
- rwskit.numpy.group_by(array: numpy.ndarray, column: str | int) list[numpy.ndarray][source]
Group an
arrayby the values in the givencolumn. Ifarrayis as structured array, thencolumnshould be the name of one of the fields, otherwise it should be the index of the column you want to use.- Parameters:
array (np.ndarray) – The array to group.
column (str | int) – If
arrayis structured thencolumnshould be the name of the column to group by. Otherwise, it should be the index of the column.
- Returns:
Returns the group as a list of arrays.
- Return type:
list