OSBinaryDataArray#
- class pyopenms.OSBinaryDataArray#
Bases:
objectCython implementation of _OSBinaryDataArray
Original C++ documentation is available here
- __init__()#
Overload:
- __init__(self) None
Overload:
- __init__(self, in_0: OSBinaryDataArray) None
Methods
Retrieve the data as a NumPy array (copy).
Retrieve the data as a memory view for fast direct access (no copy).
Attributes
- data#
- description#
- get_data()#
Retrieve the data as a NumPy array (copy).
This method creates a copy of the underlying data, so it’s safe to use even after the original object is deleted or modified.
- Returns:
np.ndarray: A NumPy array (float64) containing a copy of the data.
- Example:
>>> da = OSBinaryDataArray() >>> da.data = [1.0, 2.0, 3.0] >>> arr = da.get_data() >>> print(arr) # [1. 2. 3.]
- get_data_mv()#
Retrieve the data as a memory view for fast direct access (no copy).
This method provides direct access to the underlying data without copying, which is more memory efficient for large datasets.
- Returns:
memoryview: A direct view of the underlying data array, or None if empty.
- Warning:
The returned memory view refers directly to the underlying data. DO NOT store the returned memory view for later use after the data array object goes out of scope, as this will lead to undefined behavior and potential crashes.
- Example:
>>> da = OSBinaryDataArray() >>> da.data = [1.0, 2.0, 3.0] >>> view = da.get_data_mv() >>> # CORRECT: Use immediately >>> total = sum(view) >>> >>> # WRONG: Don't do this! >>> # stored_view = da.get_data_mv() >>> # del da # Memory view now points to invalid memory! >>> # print(stored_view[0]) # Undefined behavior/crash