pysdic.Connectivity.remove_elements#
- Connectivity.remove_elements(indices, inplace=False)[source]#
Remove elements from the connectivity based on their indices.
This method returns a new
Connectivityobject with the elements at the specified indices removed. The properties associated with the elements are also updated accordingly.See also
keep_elements()for keeping elements at specified indices.filter_elements()for filtering elements based on a boolean mask.
- Parameters:
indices (ArrayLike) – A 1D NumPy array of integer indices representing the elements to be removed from the connectivity.
inplace (
bool, optional) – IfTrue, modifies the current connectivity in place and returns itself. IfFalse, returns a newConnectivityinstance (default isFalse).
- Returns:
A new
Connectivityobject with the elements at the specified indices removed or the modified current instance if inplace is True.- Return type:
- Raises:
ValueError – If any index is out of bounds or if the input is not a 1D array of integers.
Examples
Create a
Connectivityfrom a random NumPy array.1import numpy as np 2from pysdic import Connectivity 3 4# Create a random connectivity with 100 elements 5random_elements = np.random.randint(0, 100, size=(100, 3)) # shape (100, 3) 6connectivity = Connectivity.from_array(random_elements)
Removing elements at indices 1 and 3.
1# Remove elements at indices 1 and 3 2indices_to_remove = np.array([1, 3]) 3new_connectivity = connectivity.remove_elements(indices_to_remove) 4print(new_connectivity.elements) 5# Output: A NumPy array of shape (98, 3) with elements at indices 1 and 3 removed