code: def get_rank(tensor):
      """Returns the tensor rank as a python `int`. The input tensor can also be
      a python array.
  
      Args:
          tensor: A Tensor or python array.
  
      Returns:
          A python `int` representing the rank of :attr:`tensor`. Returns
          `None` if the rank cannot be determined.
      """
      if tf.contrib.framework.is_tensor(tensor):
          shape = tensor.shape
          try:
              rank = len(shape.as_list())
          except ValueError:  # when `shape==TensorShape(None)`
              rank = None
      else:
          array = np.asarray(tensor)
          rank = array.ndim
      return rank
  
file_path: texar/texar/tf/utils/shapes.py
imports: import numpy
  import tensorflow
  from tensorflow.python.util import nest
  from tensorflow.python.ops import rnn
  from tensorflow.python.framework import ops
label_desc: Use image node_id 3 for calling a global function with example usage: get_rank(tensor) and returns: rank