code: def vec2vec_rotmat(u, v):
      r"""rotation matrix from 2 unit vectors
  
      u, v being unit 3d vectors return a 3x3 rotation matrix R than aligns u to
      v.
  
      In general there are many rotations that will map u to v. If S is any
      rotation using v as an axis then R.S will also map u to v since (S.R)u =
      S(Ru) = Sv = v.  The rotation R returned by vec2vec_rotmat leaves fixed the
      perpendicular to the plane spanned by u and v.
  
      The transpose of R will align v to u.
  
      Parameters
      ----------
      u : array, shape(3,)
      v : array, shape(3,)
  
      Returns
      -------
      R : array, shape(3,3)
  
      Examples
      --------
      >>> import numpy as np
      >>> from dipy.core.geometry import vec2vec_rotmat
      >>> u=np.array([1,0,0])
      >>> v=np.array([0,1,0])
      >>> R=vec2vec_rotmat(u,v)
      >>> np.dot(R,u)
      array([ 0.,  1.,  0.])
      >>> np.dot(R.T,v)
      array([ 1.,  0.,  0.])
  
      """
      # Cross product is the first step to find R
      # Rely on numpy instead of manual checking for failing
      # cases
      w = np.cross(u, v)
      wn = np.linalg.norm(w)
  
      # Check that cross product is OK and vectors
      # u, v are not collinear (norm(w)>0.0)
      if np.isnan(wn) or wn < np.finfo(float).eps:
          norm_u_v = np.linalg.norm(u - v)
          # This is the case of two antipodal vectors:
          # ** former checking assumed norm(u) == norm(v)
          if norm_u_v > np.linalg.norm(u):
              return -np.eye(3)
          return np.eye(3)
  
      # if everything ok, normalize w
      w = w / wn
  
      # vp is in plane of u,v,  perpendicular to u
      vp = v - (np.dot(u, v) * u)
      vp = vp / np.linalg.norm(vp)
  
      # (u vp w) is an orthonormal basis
      P = np.array([u, vp, w])
      Pt = P.T
      cosa = np.clip(np.dot(u, v), -1, 1)
      sina = np.sqrt(1 - cosa**2)
      R = np.array([[cosa, -sina, 0], [sina, cosa, 0], [0, 0, 1]])
      Rp = np.dot(Pt, np.dot(R, P))
  
      # make sure that you don't return any Nans
      # check using the appropriate tool in numpy
      if np.any(np.isnan(Rp)):
          return np.eye(3)
  
      return Rp
  
imports: import itertools
  import math
  import numpy
  import numpy.linalg
label_desc: Use image node_id 17 for calling a global function with example usage: vec2vec_rotmat(u, v) and returns: Rp, np, np, unknown