code: def _FlatOuterDims(tensor, ndims=2):
      shape = list(tensor.shape)
      return tensor.reshape(
          shape[: ndims - 1]
          + [
              functools.reduce(
                  lambda x, y: x * y, shape[ndims - 1 :], 1
              )
          ]
      )
  
imports: import functools
  import numpy
  from tensorflow.compiler.tests import xla_test
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 3 for calling a global function with example usage: _FlatOuterDims(tensor, ndims) and returns: tensor