code: def conv2bin(data):
      
      if data.min() < 0 or data.max() > 1:
          data = normalize(data)
  
      out_data = data.copy()
  
      for i, sample in enumerate(out_data):
  
          for j, val in enumerate(sample):
  
              if np.random.random() <= val:
                  out_data[i][j] = 1
              else:
                  out_data[i][j] = 0
  
      return out_data
docs: Convert a matrix of probabilities into binary values.
  
      If the matrix has values <= 0 or >= 1, the values are
      normalized to be in [0, 1].
  
      :type data: numpy array
      :param data: input matrix
      :return: converted binary matrix