code: def _one_hot(data):
      """Encodes columns of a numpy array as one-hot.
  
      Args:
        data: A numpy array of rank 2. Every column is a categorical feature and
          every row is a sample.
  
      Returns:
        A 0/1 numpy array of rank 2 containing the same number of rows as the input.
        The number of columns is equal to the sum of distinct elements per column of
        the input array.
      """
      num_rows, num_cols = np.shape(data)
      encoded = np.array([], dtype=np.int32).reshape((num_rows, 0))
      for i in range(num_cols):
          vocabulary = sorted(list(set(data[:, i])))
          lookup = dict(
              list(zip(vocabulary, list(range(len(vocabulary)))))
          )
          int_encoded = np.array([lookup[x] for x in data[:, i]])
          new_cols = np.eye(len(vocabulary), dtype=np.int32)[
              int_encoded
          ]
          encoded = np.append(encoded, new_cols, axis=1)
      return encoded
  
file_path: agents/tf_agents/bandits/environments/dataset_utilities.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import csv
  import gin
  import numpy
  from six.moves import range
  from six.moves import zip
  import tensorflow
  import tensorflow_probability
label_desc: Use image node_id 2 for calling a global function with example usage: _one_hot(data) and returns: encoded