mlnext.utils.check_shape#

mlnext.utils.check_shape(*arrays: ndarray, shape: Tuple[int, ...] | None = None, exclude_axis: int | None = None)[source]#

Checks the shape of one or more arrays. If shape is not None, all arrays must match shape. Otherwise shape is set to the shape of the first array. With exclude_axis, an axis can be excluded from the check.

Parameters:
  • shape (T.Optional[T.Tuple[int, ...]], optional) – Shape to match. If not defined, then the shape of the first array is taken. Defaults to None.

  • exclude_axis (T.Optional[int], optional) – Excludes an axis from the check. Shape must be defined without the axis. Defaults to None.

Raises:

ValueError – Raised if an array has the wrong shape.

Example

>>> mlnext.utils.check_shape([np.zeros((1, 2)), np.ones((2, 2)),
...                           shape=(2,), exclude_axis=0)