code: def _second_order(B2, Y_res, C2, R, n2, m2, lambdax):
      """Compute second order sensitivities."""
      Y_ij = np.empty((R, n2))  # Initialize 2nd order contributions
      T2 = np.empty((m2, R))  # Initialize T(emporary) matrix - 1st
  
      lam_eye_m2 = lambdax * identity(m2)
  
      # Avoid memory allocations by using temporary store
      B2_j = np.empty(B2[:, :, 0].shape)
      B22 = np.empty((m2, m2))
  
      # First order individual estimation
      for j in range(n2):
          # Regularized least squares inversion ( minimize || C1 ||_2 )
          B2_j[:, :] = B2[:, :, j]
          B22[:, :] = B2_j.T @ B2_j
  
          # if it is ill-conditioned matrix, the default value is zero
          if np.all(svd(B22)[1]):  # sigma, diagonal matrix, from svd
              T2[:, :] = lin_solve(B22 + lam_eye_m2, B2_j.T)
          else:
              T2[:, :] = 0.0
  
          C2[:, j] = T2 @ Y_res
          Y_ij[:, j] = B2_j @ C2[:, j]
  
      # Now compute second-order terms
      for j in range(n2):
          # Subtract each first order term from residuals
          Y_res = Y_res - Y_ij[:, j]
  
      return (Y_ij, Y_res, C2)
  
imports: from typing import Dict
  from types import MethodType
  import itertools
  import time
  import warnings
  import numpy
  from numpy.linalg import solve
  from numpy.linalg import svd
  from numpy import identity
  import pandas
  from scipy import stats, special, interpolate
  from .None import common_args
  from ..util import read_param_file, ResultDict
  from SALib.plotting.hdmr import plot
  from SALib.util.problem import ProblemSpec
label_desc: Use image node_id 7 for calling a global function with example usage: _second_order(B2, Y_res, C2, R, n2, m2, lambdax) and returns: Y_ij,  Y_res,  C2