code: def gray_code_masks(nbits):
      """Produces an array of all binary patterns of size nbits in gray code order.
  
      This is based on code from: http://code.activestate.com/recipes/576592-gray-code-generatoriterator/
      """
      out = np.zeros((2**nbits, nbits), dtype=bool)
      li = np.zeros(nbits, dtype=bool)
  
      for term in range(2, (1 << nbits) + 1):
          if term % 2 == 1:  # odd
              for i in range(-1, -nbits, -1):
                  if li[i] == 1:
                      li[i - 1] = li[i - 1] ^ 1
                      break
          else:  # even
              li[-1] = li[-1] ^ 1
  
          out[term - 1, :] = li
      return out
  
file_path: shap/shap/explainers/_exact.py
imports: import logging
  import numpy
  from numba import njit
  from ..None import links
  from ..models import Model
  from ..utils import MaskedModel, delta_minimization_order, make_masks, shapley_coefficients
  from ._explainer import Explainer
label_desc: Use image node_id 6 for calling a global function with example usage: gray_code_masks(nbits) and returns: out