code: def affine_transform(geom, matrix):
      r"""Return a transformed geometry using an affine transformation matrix.
  
      The coefficient matrix is provided as a list or tuple with 6 or 12 items
      for 2D or 3D transformations, respectively.
  
      For 2D affine transformations, the 6 parameter matrix is::
  
          [a, b, d, e, xoff, yoff]
  
      which represents the augmented matrix::
  
          [x']   / a  b xoff \ [x]
          [y'] = | d  e yoff | [y]
          [1 ]   \ 0  0   1  / [1]
  
      or the equations for the transformed coordinates::
  
          x' = a * x + b * y + xoff
          y' = d * x + e * y + yoff
  
      For 3D affine transformations, the 12 parameter matrix is::
  
          [a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]
  
      which represents the augmented matrix::
  
          [x']   / a  b  c xoff \ [x]
          [y'] = | d  e  f yoff | [y]
          [z']   | g  h  i zoff | [z]
          [1 ]   \ 0  0  0   1  / [1]
  
      or the equations for the transformed coordinates::
  
          x' = a * x + b * y + c * z + xoff
          y' = d * x + e * y + f * z + yoff
          z' = g * x + h * y + i * z + zoff
      """
      if len(matrix) == 6:
          ndim = 2
          a, b, d, e, xoff, yoff = matrix
          if geom.has_z:
              ndim = 3
              i = 1.0
              c = f = g = h = zoff = 0.0
      elif len(matrix) == 12:
          ndim = 3
          a, b, c, d, e, f, g, h, i, xoff, yoff, zoff = matrix
          if not geom.has_z:
              ndim = 2
      else:
          raise ValueError(
              "'matrix' expects either 6 or 12 coefficients"
          )
      if ndim == 2:
          A = np.array([[a, b], [d, e]], dtype=float)
          off = np.array([xoff, yoff], dtype=float)
      else:
          A = np.array([[a, b, c], [d, e, f], [g, h, i]], dtype=float)
          off = np.array([xoff, yoff, zoff], dtype=float)
  
      def _affine_coords(coords):
          return np.matmul(A, coords.T).T + off
  
      return shapely.transform(
          geom, _affine_coords, include_z=ndim == 3
      )
  
file_path: shapely/shapely/affinity.py
imports: from math import cos, pi, sin, tan
  import numpy
  import shapely
label_desc: Use image node_id 1 for calling a global function with example usage: affine_transform(geom, matrix) and returns: shapely, unknown