code: def _normalize_data(data, index):
      """normalize the data to a dict with tuples of strings as keys
      right now it works with:
  
          0 - dictionary (or equivalent mappable)
          1 - pandas.Series with simple or hierarchical indexes
          2 - numpy.ndarrays
          3 - everything that can be converted to a numpy array
          4 - pandas.DataFrame (via the _normalize_dataframe function)
      """
      # if data is a dataframe we need to take a completely new road
      # before coming back here. Use the hasattr to avoid importing
      # pandas explicitly
      if hasattr(data, "pivot") and hasattr(data, "groupby"):
          data = _normalize_dataframe(data, index)
          index = None
      # can it be used as a dictionary?
      try:
          items = list(data.items())
      except AttributeError:
          # ok, I cannot use the data as a dictionary
          # Try to convert it to a numpy array, or die trying
          data = np.asarray(data)
          temp = {}
          for idx in np.ndindex(data.shape):
              name = tuple(i for i in idx)
              temp[name] = data[idx]
          data = temp
          items = list(data.items())
      # make all the keys a tuple, even if simple numbers
      data = {_tuplify(k): v for k, v in items}
      categories_levels = _categories_level(list(data.keys()))
      # fill the void in the counting dictionary
      indexes = product(*categories_levels)
      contingency = {k: data.get(k, 0) for k in indexes}
      data = contingency
      # reorder the keys order according to the one specified by the user
      # or if the index is None convert it into a simple list
      # right now it does not do any check, but can be modified in the future
      index = lrange(len(categories_levels)) if index is None else index
      contingency = {}
      for key, value in data.items():
          new_key = tuple(key[i] for i in index)
          contingency[new_key] = value
      data = contingency
      return data
  
imports: from statsmodels.compat.python import lrange, lzip
  from itertools import product
  import numpy
  from numpy import array, cumsum, iterable, r_
  from pandas import DataFrame
  from statsmodels.graphics import utils
label_desc: Use image node_id 10 for calling a global function with example usage: _normalize_data(data, index) and returns: data