pysdic.Connectivity.keep_elements#
- Connectivity.keep_elements(indices, inplace=False)[source]#
Keep only the elements at the specified indices in the connectivity.
This method returns a new
Connectivityobject containing only the elements at the specified indices. The properties associated with the elements are also filtered accordingly.See also
remove_elements()for removing elements at specified indices.filter_elements()for filtering elements based on a boolean mask.
- Parameters:
- Returns:
A new
Connectivityobject containing only the elements at the specified indices or the modified current instance ifinplaceis 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)
Keeping only the points at indices 0, 2, and 4.
1# Keep only elements at indices 0, 2, and 4 2indices_to_keep = np.array([0, 2, 4]) 3new_connectivity = connectivity.keep_elements(indices_to_keep) 4print(new_connectivity.elements) 5# Output: A NumPy array of shape (3, 3) containing only the elements at indices 0, 2, and 4