def _compute_pert(theta: np.ndarray, grads: np.ndarray, norm_grad: np.ndarray) -> np.ndarray:
        """
        Function to compute the perturbation at each step.

        :param theta: Theta value at the current step.
        :param grads: Gradient values at the attacked class.
        :param norm_grad: Norm of gradient values at the attacked class.
        :return: Computed perturbation.
        """
        # Pick a small scalar to avoid division by 0
        tol = 10e-8

        nom = -theta.reshape((-1,) + (1,) * (len(grads.shape) - 1)) * grads
        denom = norm_grad**2
        denom[denom < tol] = tol
        result = nom / denom.reshape((-1,) + (1,) * (len(grads.shape) - 1))

        return result

        Function to compute the perturbation at each step.

        :param theta: Theta value at the current step.
        :param grads: Gradient values at the attacked class.
        :param norm_grad: Norm of gradient values at the attacked class.
        :return: Computed perturbation.
        
art/attacks/evasion/newtonfool.py