rwskit.numpy

Numpy utilities.

Attributes

log

CompleteCheckType

The valid values for the check_type parameter of is_complete().

Functions

get_dtype(→ Optional[numpy.dtype])

Return a dtype that can be used to represent an arbitrary object.

is_structured(→ bool)

Checks if a numpy array is a structured array or not.

is_complete(→ bool)

An array is complete if all its numeric values are finite and all other

finite_cases(→ numpy.ndarray)

Return only the rows whose values are finite and not None.

group_by(→ list[numpy.ndarray])

Group an array by the values in the given column. If array is

Module Contents

rwskit.numpy.log[source]
rwskit.numpy.CompleteCheckType[source]

The valid values for the check_type parameter of is_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 return None.

Parameters:

obj (Any) – An object.

Returns:

A dtype that can be used to represent an arbitrary object, or None if the input object is None.

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:

True if the array is a structured array, False otherwise.

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 is None.

Parameters:
  • check_type ({"finite", "nan"}) –

    Determines how completeness is defined.

    nan

    Requires that no values are np.NaN or None.

    finite

    In addition to the criteria for nan all values must also be finite (i.e., not np.inf or -np.inf).

  • array (np.ndarray) – The array to check.

Returns:

True if the array is complete, False otherwise.

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 array by the values in the given column. If array is as structured array, then column should 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 array is structured then column should 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