pyxc.core.processor.arrays
Module Contents
Functions
|
Reshape the provided array if it's one-dimensional. |
|
Label X- and Y-indices of the provided image. |
|
Flatten image to tuple(s). |
Return field names from the provided dtype_object based on the integer indices. |
|
|
Return (n, 3) shaped array after receiving two (n,) shaped arrays. |
|
Extract the first (x) and second (y) columns from the provided (n, 3) shaped array. |
|
Return a structured array based on the given integer indices. |
|
Re-order the provided array_like object with respect to the format string. |
|
Split a structured array into three separate arrays. |
- pyxc.core.processor.arrays.reshape_if_1dim(array: numpy.ndarray, is_structured=False) numpy.ndarray[source]
Reshape the provided array if it’s one-dimensional.
If the shape of the provided array is (n, ), then it will be reshaped to (n, 1). If the array is two-dimensional or is a structured array, it will be returned as is. Otherwise, a ValueError will be raised.
- Parameters:
- array
np.ndarray The input array to be reshaped.
- is_structuredbool, default=False
A boolean flag indicating whether the input array is structured.
- array
- Returns:
np.ndarrayThe reshaped array.
- Raises:
ValueErrorIf the dimensions of the input array are either too low or too high.
- pyxc.core.processor.arrays.image_notator(image: numpy.typing.ArrayLike, channel: int | None = None) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]
Label X- and Y-indices of the provided image.
- Parameters:
- imagearray_like or
np.ndarray A 2D or 3D array-like object representing the image. For 3D arrays, the last dimension should be the channel.
- channel
int, optional Specifies the channel to be considered if the input image is a 3D array. If None (default), all channels are considered.
- imagearray_like or
- Returns:
tupleofnp.ndarrayA tuple containing: - X-indices of the image as a ndarray - Y-indices of the image as a ndarray - The supplied image or its specific channel as a ndarray
- Raises:
ValueErrorIf the dimension of the input image is not 2D or 3D.
- pyxc.core.processor.arrays.image_serializer(image: numpy.typing.ArrayLike) tuple[numpy.ndarray, Ellipsis][source]
Flatten image to tuple(s).
Return flattened image from the supplied image.
- Parameters:
- imagearray_like
2-dimensional or 3-dimensional array-like image.
- Returns:
tuple[np.ndarray, …]Flattened image. Each row contains image information.
- pyxc.core.processor.arrays.get_structured_array_field_names_from_indices(dtype_object: numpy.dtype, indices: Sequence[int]) tuple[str, Ellipsis][source]
Return field names from the provided dtype_object based on the integer indices.
- pyxc.core.processor.arrays.xy2matrix(x: numpy.typing.ArrayLike, y: numpy.typing.ArrayLike) numpy.ndarray[source]
Return (n, 3) shaped array after receiving two (n,) shaped arrays.
- Parameters:
- xarray_like
NumPy array contains x-coordinate values.
- yarray_like
NumPy array contains y-coordinate values.
- Returns:
- pyxc.core.processor.arrays.matrix2xy(matrix_like_array: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray][source]
Extract the first (x) and second (y) columns from the provided (n, 3) shaped array.
- Parameters:
- matrix_like_array
np.ndarray (n, 3) shaped array. First and second columns are x and y coordinates.
- matrix_like_array
- Returns:
np.ndarrayx-coordinates
np.ndarrayy-coordinates
- pyxc.core.processor.arrays.structured_array_query(structured_array: numpy.ndarray, indices: Sequence[int]) numpy.ndarray[source]
Return a structured array based on the given integer indices.
Get a subset of the structured array based on given indices. Usually, column slicing of the structured array is performed using key values. This function provides structured array column slicing by integer column indices.
- Parameters:
- structured_array
np.ndarray Structured array.
- indices
Sequence[int, …] A sequence of integer column indices.
- structured_array
- Returns:
np.ndarrayStructured array.
- pyxc.core.processor.arrays.column_parser(array: numpy.typing.ArrayLike, format_string: str, return_unspecified=True) numpy.ndarray[source]
Re-order the provided array_like object with respect to the format string.
- Parameters:
- arrayarray_like
2-dimensional array or structured array.
- format_string
str A Format string. See Notes section.
- return_unspecifiedbool, default=True
If False, the unspecified portion of columns will NOT be returned together. See Notes.
- Returns:
np.ndarrayRe-ordered np.ndarray respective with the provided format string.
- Raises:
ValueErrorWhen the provided format string or the provided array-like object is not right.
Notes
A format string key-letter is x, y, and _. Each letter corresponds to x-coordinates, y-coordinates, and columns to be ignored. All other characters than x, y, and _ will be treated as valid columns.
If return_unspecified is False, then unspecified columns won’t be returned together. For example, when the format string is given by yxd__dd and the provided array is a structured array with column names of (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), then this function returns columns (2, 1, 3, 6, 7, 8, 9, 10) by default. However, when return_unspecified is False, then this function returns (2, 1, 3, 6, 7) only.
- pyxc.core.processor.arrays.xyd_splitter(array: numpy.typing.ArrayLike) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]
Split a structured array into three separate arrays.
- Parameters:
- arrayarray_like
Array-like object to be split. If it is a structured array, then the number of columns should be greater than or equal to 3.
- Returns:
np.ndarrayX-coordinates. Unstructured array. Shape is (n, )
np.ndarrayY-coordinates. Unstructured array. Shape is (n, )
np.ndarrayData array. If the initially given
arrayand number of the columns is greater than or equal to 4 in the structured array, then return a structured array. Else, return a 2-dimensional unstructured array.
- Raises:
ValueErrorIf the input array has less than three columns.