keras/src/backend/numpy/random.py/dropout
def dropout(inputs, rate, noise_shape=None, seed=None):
    dtype = inputs.dtype
    seed = draw_seed(seed)

    keep_prob = 1.0 - rate

    # If noise_shape is not provided, use the shape of inputs
    if noise_shape is None:
        noise_shape = inputs.shape
    else:
        # If noise_shape is provided, replace None with corresponding
        # input shape
        noise_shape = [
            n if n is not None else inputs.shape[i]
            for i, n in enumerate(noise_shape)
        ]

    rng = np.random.default_rng(seed)
    mask = rng.uniform(size=noise_shape) < keep_prob
    mask = np.broadcast_to(mask, inputs.shape)
    return np.where(
        mask, (inputs / keep_prob).astype(dtype), np.zeros_like(inputs)
    )