code: def _spectral_norm(
      w,
      dim=0,
      itr=1,
      eps=1e-12,
      test=False,
      u_init=None,
      fix_parameters=True,
  ):
      # Use the original shape for W_sn
      w_shape = w.shape
      W_sn = get_parameter_or_create(
          "W_sn", w_shape, ConstantInitializer(0), False
      )
      # Transpose if the output dimension is not the most-left dimension.
      if dim != 0:
          dims_transpose = [dim] + [
              i for i in range(len(w_shape)) if i != dim
          ]
          w = F.transpose(w, dims_transpose)
          w_shape = w.shape
      d0 = w.shape[0]  # Out
      d1 = np.prod(w.shape[1:])  # In
      w = F.reshape(w, [d0, d1])
      if u_init is None:
          u_init = NormalInitializer()
      u0 = get_parameter_or_create("u", [d0], u_init, False, False)
      u = F.reshape(u0, [1, d0])
  
      # Ensure both parameters (W_sn and u) exist when the test is called fast.
      if test:
          return W_sn
      # Power method
      for _ in range(itr):
          # v
          v = F.affine(u, w)
          v = v / ((F.sum(v**2.0, keepdims=True) + eps) ** 0.5)
          v = F.reshape(v, [d1, 1])
          # u
          u = F.affine(w, v)
          u = u / ((F.sum(u**2.0, keepdims=True) + eps) ** 0.5)
          u = F.reshape(u, [1, d0])
      # Iterate
      u = F.identity(u, outputs=[u0.data])
      u.persistent = True
      # No grad
      u.need_grad = False
      v.need_grad = False
      # Spectral normalization
      wv = F.affine(w, v)
      sigma = F.affine(u, wv)
      w_sn = w / sigma
      w_sn = F.reshape(w_sn, w_shape)
      # Transpose again if the output dimension is not the most-left dimension.
      if dim != 0:
          dims_transpose = (
              [i for i in range(1, dim + 1)]
              + [0]
              + [i for i in range(dim + 1, len(w_shape))]
          )
          w_sn = F.transpose(w_sn, dims_transpose)
      w_sn = F.identity(w_sn, outputs=[W_sn.data])
      w_sn.persistent = True
      return w_sn
  
imports: from six import exec_
  import numpy
  import nnabla
  import nnabla.functions
  from nnabla.parameter import get_parameter_or_create, get_parameter
  from nnabla.initializer import calc_uniform_lim_glorot, ConstantInitializer, NormalInitializer, UniformInitializer, WeightNormalizationScaleInitializer
label_desc: Use image node_id 41 for calling a global function with example usage: _spectral_norm(w, dim, itr, eps, test, u_init, fix_parameters) and returns: w_sn, W_sn