sarcomp.sub#
- sarcomp.sub(array0: ndarray | Array, array1: ndarray | Array, new=False) Array #
Element-wise subtraction of two arrays.
This function performs element-wise subtraction of two input arrays, which can be numpy ndarrays or instances of the custom Array class. If both inputs are numpy ndarrays, the output will be a numpy ndarray. If at least one input is an instance of the custom Array class, the output will be an instance of the custom Array class. If new is set to True, a new array is returned, leaving the original arrays unchanged. Otherwise, the result is stored in array0.
- Parameters:
array0 (Union[np.ndarray, Array]) – The first input array.
array1 (Union[np.ndarray, Array]) – The second input array.
new (bool, optional) – If True, returns a new array without modifying the original input arrays. Default is False.
- Returns:
An array containing the element-wise difference of array0 and array1.
- Return type:
np.ndarray or Array
- Raises:
ValueError – If the shapes of the input arrays are not compatible for element-wise subtraction.
Examples
>>> import numpy as np >>> import sarcomp as sc
>>> np_array0 = np.array([5, 7, 9]).astype('f4') >>> np_array1 = np.array([4, 5, 6]).astype('f4') >>> sc.sub(np_array0, np_array1) # inplace methods (nparray0)
Notes
The shapes of the input arrays must be compatible for element-wise subtraction.
If both input arrays are numpy ndarrays, the output will also be a numpy ndarray.
If at least one input array is an instance of the custom Array class, the output will be an instance of the custom Array class.