code: def generate_basis(z):
      
      # get a copy of input vector
      z = np.array(z, dtype=np.float64, copy=True)
      # must be a 3D vector
      if z.shape != (3,):
          raise ValueError('z must be (3,) float!')
  
      # normalize vector in- place
      z /= np.linalg.norm(z)
      # X as arbitrary perpendicular vector
      x = np.array([-z[1], z[0], 0.0])
      # avoid degenerate case
      if np.isclose(np.linalg.norm(x), 0.0):
          # Z is already along Z [0, 0, 1]
          # so a perpendicular X is just X
          x = np.array([1.0, 0.0, 0.0])
      else:
          # otherwise normalize X in- place
          x /= np.linalg.norm(x)
      # get perpendicular Y with cross product
      y = np.cross(z, x)
      # append result values into vector
      result = np.array([x, y, z], dtype=np.float64)
  
      return result
docs: Generate an arbitrary basis (also known as a coordinate frame)
      from a given z-axis vector.
  
      Parameters
      ----------
      z: (3,) float
        A vector along the positive z-axis
  
      Returns
      -------
      x : (3,) float
        Vector along x axis
      y : (3,) float
        Vector along y axis
      z : (3,) float
        Vector along z axis