sarcomp.add#

sarcomp.add(array0: ndarray | Array, array1: ndarray | Array, new=False) Array#

Element-wise addition of two arrays.

This function performs element-wise addition 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 sum 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 addition.

Examples

>>> import numpy as np
>>> import sarcomp as sc
>>> np_array0 = np.array([1, 2, 3])
>>> np_array1 = np.array([4, 5, 6])
>>> sc.add(np_array0, np_array1) # inplace methods (nparray0)

Notes

  • The shapes of the input arrays must be compatible for element-wise addition.

  • 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.