code: def _ndims_from_shape(shape):
      """Returns `Tensor`'s `rank` implied by a `Tensor` shape."""
      if shape.get_shape().ndims not in (None, 1):
          raise ValueError("input is not a valid shape: not 1D")
      if not shape.dtype.is_integer:
          raise TypeError("input is not a valid shape: wrong dtype")
      if shape.get_shape().is_fully_defined():
          return constant_op.constant(shape.get_shape().as_list()[0])
      return array_ops.shape(shape)[0]
  
imports: import numpy
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import array_ops_stack
  from tensorflow.python.ops import check_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops.distributions import distribution
  from tensorflow.python.ops.distributions import identity_bijector
  from tensorflow.python.ops.distributions import util
  from tensorflow.python.util import deprecation
label_desc: Use image node_id 8 for calling a global function with example usage: _ndims_from_shape(shape) and returns: array_ops, constant_op