def validate_anomaly_map(anomaly_map: np.ndarray | None) -> np.ndarray | None:
        """Validate the anomaly map.

        Validates and normalizes input anomaly map arrays.

        Args:
            anomaly_map (``np.ndarray`` | ``None``): Input anomaly map.

        Returns:
            ``np.ndarray`` | ``None``: Validated anomaly map as float32 array, or None.

        Raises:
            TypeError: If ``anomaly_map`` is not a numpy array.
            ValueError: If ``anomaly_map`` dimensions are invalid.

        Example:
            Validate an anomaly map::

                >>> import numpy as np
                >>> from anomalib.data.validators import NumpyImageValidator
                >>> anomaly_map = np.random.rand(224, 224)
                >>> validated_map = NumpyImageValidator.validate_anomaly_map(anomaly_map)
                >>> validated_map.shape
                (224, 224)

        Note:
            - 3D maps with shape (1,H,W) are squeezed to (H,W)
            - Output is always float32 type
            - None inputs return None
        """
        if anomaly_map is None:
            return None
        if not isinstance(anomaly_map, np.ndarray):
            msg = f"Anomaly map must be a numpy array, got {type(anomaly_map)}."
            raise TypeError(msg)
        if anomaly_map.ndim not in {2, 3}:
            msg = f"Anomaly map must have shape [H, W] or [1, H, W], got shape {anomaly_map.shape}."
            raise ValueError(msg)
        if anomaly_map.ndim == 3:
            if anomaly_map.shape[0] != 1:
                msg = f"Anomaly map with 3 dimensions must have 1 channel, got {anomaly_map.shape[0]}."
                raise ValueError(msg)
            anomaly_map = anomaly_map.squeeze(0)
        return anomaly_map.astype(np.float32)
Validate the anomaly map.

        Validates and normalizes input anomaly map arrays.

        Args:
            anomaly_map (``np.ndarray`` | ``None``): Input anomaly map.

        Returns:
            ``np.ndarray`` | ``None``: Validated anomaly map as float32 array, or None.

        Raises:
            TypeError: If ``anomaly_map`` is not a numpy array.
            ValueError: If ``anomaly_map`` dimensions are invalid.

        Example:
            Validate an anomaly map::

                >>> import numpy as np
                >>> from anomalib.data.validators import NumpyImageValidator
                >>> anomaly_map = np.random.rand(224, 224)
                >>> validated_map = NumpyImageValidator.validate_anomaly_map(anomaly_map)
                >>> validated_map.shape
                (224, 224)

        Note:
            - 3D maps with shape (1,H,W) are squeezed to (H,W)
            - Output is always float32 type
            - None inputs return None
        
src/anomalib/data/validators/numpy/image.py