pysdic.Connectivity.filter_elements#
- Connectivity.filter_elements(mask, inplace=False)[source]#
Filter elements in the connectivity based on a boolean mask.
This method returns a new
Connectivityobject containing only the elements where the mask is True. The mask should be a 1D boolean NumPy array with the same length as the number of elements in the connectivity. All the properties associated with the elements are also filtered accordingly.See also
keep_elements()for keeping elements at specified indices.remove_elements()for removing elements at specified indices.
- Parameters:
mask (ArrayLike) – A 1D boolean NumPy array of shape \((N_e,)\) where \(N_e\) is the number of elements in the connectivity. Each element should be True to keep the corresponding element, or False to remove it.
inplace (
bool, optional) – IfTrue, modifies the current connectivity in place and returns itself. IfFalse, returns a newConnectivityinstance (default isFalse).
- Returns:
A new
Connectivityobject containing only the filtered elements or the modified current instance ifinplaceis True.- Return type:
- Raises:
ValueError – If the input mask is not a 1D boolean array of the correct length.
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)
Filtering elements with any vertex index greater than 50.
1# Create a boolean mask for elements with any vertex index greater than 50 2mask = (connectivity.elements > 50).any(axis=1) 3 4# Filter the connectivity using the mask 5filtered_connectivity = connectivity.filter_elements(mask) 6print(filtered_connectivity.elements) 7# Output: A NumPy array containing only the elements with any vertex index greater than 50