pysdic.Connectivity.from_array#

classmethod Connectivity.from_array(elements, copy=False, properties=None, element_type=None)[source]#

Create a Connectivity object from a NumPy array of shape \((N_e, N_vpe)\).

See also

  • to_array() method for converting the connectivity back to a NumPy array.

Parameters:
  • elements (ArrayLike) – A NumPy array of shape \((N_e, N_vpe)\) representing the connectivity elements.

  • copy (bool, optional) – If True, a copy of the input array is made. Default is False. If the given object is not a type numpy.int64 array, a copy will be made regardless of this parameter.

  • properties (Optional[Dict[str, ArrayLike]], optional) – A dictionary of additional properties to associate with the connectivity. Keys are property names, and values are NumPy arrays of property data of shape \((N_e, A)\).

  • element_type (Optional[str], optional) – The expected type of elements in the connectivity. If provided, the connectivity will enforce that all elements are of the specified type. Default is None.

Returns:

A Connectivity object containing the provided elements.

Return type:

Connectivity

Raises:
  • TypeError – If the input elements is not a NumPy array. If the properties is not a dictionary. If the element type is not a string.

  • ValueError – If the input array does not have the correct shape \((N_e, N_vpe)\). If the properties arrays do not have the correct shape \((N_e, A)\). If the element type is not one of the implemented types.

Examples

Creating a Connectivity object 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, 4))  # shape (100, 4)
6connectivity = Connectivity.from_array(random_elements)

Now, connectivity is a Connectivity object containing the elements from the NumPy array.