code: def create_affine_pixdim(affine, pixdim):
      """
      Given an existing affine transformation and the pixel dimension to apply,
      create a new affine matrix that satisfies the new pixel dimension.
  
      :param affine: original affine matrix
      :param pixdim: pixel dimensions to apply
      :return:
      """
      norm_affine = np.sqrt(np.sum(np.square(affine[:, 0:3]), 0))
      to_divide = np.tile(
          np.expand_dims(np.append(norm_affine, 1), axis=1), [1, 4]
      )
      to_multiply = np.tile(
          np.expand_dims(np.append(np.asarray(pixdim), 1), axis=1),
          [1, 4],
      )
      return np.multiply(np.divide(affine, to_divide.T), to_multiply.T)
  
imports: from __future__ import absolute_import, print_function, unicode_literals
  import errno
  import importlib
  import logging
  import os
  import re
  import sys
  import warnings
  import nibabel
  import numpy
  import pandas
  import scipy.ndimage
  import tensorflow
  from tensorflow.core.framework import summary_pb2
  from niftynet.io.image_loader import load_image_obj
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_import import require_module
label_desc: Use image node_id 3 for calling a global function with example usage: create_affine_pixdim(affine, pixdim) and returns: np