code: def unitvec(vec):
      """
      Scale a vector to unit length. The only exception is the zero vector, which
      is returned back unchanged.
      """
      if scipy.sparse.issparse(
          vec
      ):  # convert scipy.sparse to standard numpy array
          vec = vec.tocsr()
          veclen = numpy.sqrt(numpy.sum(vec.data**2))
          if veclen > 0.0:
              return vec / veclen
          else:
              return vec
  
      if isinstance(vec, numpy.ndarray):
          vec = numpy.asarray(vec, dtype=float)
          veclen = numpy.linalg.norm(vec)
          if veclen > 0.0:
              return vec / veclen
          else:
              return vec
  
imports: import sys
  import numpy
  import scipy
label_desc: Use image node_id 2 for calling a global function with example usage: unitvec(vec) and returns: unknown, vec, unknown, vec