turboflow.utilities.numerics module
- turboflow.utilities.numerics.check_lists_match(list1, list2)[source]
Check if two lists contain the exact same elements, regardless of their order.
- Parameters:
- list1list
The first list for comparison.
- list2list
The second list for comparison.
- Returns:
- bool
Returns True if the lists contain the exact same elements, regardless of their order. Returns False otherwise.
Examples
>>> check_lists_match([1, 2, 3], [3, 2, 1]) True
>>> check_lists_match([1, 2, 3], [4, 5, 6]) False
- turboflow.utilities.numerics.ensure_iterable(obj)[source]
Ensure that an object is iterable. If the object is already an iterable (except for strings, which are not treated as iterables in this context), it will be returned as is. If the object is not an iterable, or if it is a string, it will be placed into a list to make it iterable.
- Parameters:
- objany type
The object to be checked and possibly converted into an iterable.
- Returns:
- Iterable
The original object if it is an iterable (and not a string), or a new list containing the object if it was not iterable or was a string.
Examples
>>> ensure_iterable([1, 2, 3]) [1, 2, 3] >>> ensure_iterable('abc') ['abc'] >>> ensure_iterable(42) [42] >>> ensure_iterable(np.array([1, 2, 3])) array([1, 2, 3])
- turboflow.utilities.numerics.extract_timestamp(filename)[source]
Extract the timestamp from the filename.
- Parameters:
- filenamestr
The filename containing the timestamp.
- Returns:
- str
The extracted timestamp.
- turboflow.utilities.numerics.fill_array_with_increment(n)[source]
Fill an array of length n with values that sum to 1, where each value is different but has the same increment between neighboring values.
- Parameters:
- nint
Length of the array.
- Returns:
- arrayndarray
Array of length ‘n’ filled with values incrementing by a constant factor, resulting in a sum of 1.
- turboflow.utilities.numerics.flatten_dataframe(df: DataFrame) DataFrame [source]
Convert a DataFrame with multiple rows and columns into a single-row DataFrame with each column renamed to include the original row index as a suffix.
Parameters: - df (pd.DataFrame): The original DataFrame to be flattened.
Returns: - pd.DataFrame: A single-row DataFrame with (n×m) columns.
Example usage: >>> original_df = pd.DataFrame({‘A’: [1, 2], ‘B’: [3, 4]}) >>> flattened_df = flatten_dataframe(original_df) >>> print(flattened_df)
Note: Row indices start at 1 for the suffix in the column names.
- turboflow.utilities.numerics.is_float(element: any) bool [source]
Check if the given element can be converted to a float.
- Parameters:
- elementany
The element to be checked.
- Returns:
- bool
True if the element can be converted to a float, False otherwise.
- turboflow.utilities.numerics.is_numeric(value)[source]
Check if a value is a numeric type, including both Python and NumPy numeric types.
This function checks if the given value is a numeric type (int, float, complex) in the Python standard library or NumPy, while explicitly excluding boolean types.
- Parameters:
- valueany type
The value to be checked for being a numeric type.
- Returns:
- bool
Returns True if the value is a numeric type (excluding booleans), otherwise False.
- turboflow.utilities.numerics.isclose_significant_digits(a, b, significant_digits)[source]
Check if two floating-point numbers are close based on a specified number of significant digits.
- Parameters:
- afloat
The first number to compare.
- bfloat
The second number to compare.
- sig_digitsint
The number of significant digits to use for the comparison.
- Returns:
- bool
True if numbers are close up to the specified significant digits, False otherwise.