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 Connectivity object containing only the elements at the specified indices. The properties associated with the elements are also filtered accordingly.

See also

Parameters:
  • indices (ArrayLike) – A 1D NumPy array of integer indices representing the elements to be kept in the connectivity.

  • inplace (bool, optional) – If True, modifies the current connectivity in place and returns itself. If False, returns a new Connectivity instance (default is False).

Returns:

A new Connectivity object containing only the elements at the specified indices or the modified current instance if inplace is True.

Return type:

Connectivity

Raises:

ValueError – If any index is out of bounds or if the input is not a 1D array of integers.

Examples

Create a Connectivity from 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