code: def _sklearn_stat_scores_multiclass_local(
      preds, target, ignore_index, average
  ):
      preds = preds.numpy()
      target = target.numpy()
  
      res = []
      for pred, true in zip(preds, target):
          pred = pred.flatten()
          true = true.flatten()
          true, pred = remove_ignore_index(true, pred, ignore_index)
          confmat = sk_confusion_matrix(
              y_true=true, y_pred=pred, labels=list(range(NUM_CLASSES))
          )
          tp = np.diag(confmat)
          fp = confmat.sum(0) - tp
          fn = confmat.sum(1) - tp
          tn = confmat.sum() - (fp + fn + tp)
          r = np.stack([tp, fp, tn, fn, tp + fn], 1)
          if average == "micro":
              res.append(r.sum(0))
          elif average == "macro":
              res.append(r.mean(0))
          elif average == "weighted":
              w = tp + fn
              res.append((r * (w / w.sum()).reshape(-1, 1)).sum(0))
          elif average is None or average == "none":
              res.append(r)
      return np.stack(res, 0)
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from torchmetrics.classification.stat_scores import BinaryStatScores, MulticlassStatScores, MultilabelStatScores, StatScores
  from torchmetrics.functional.classification.stat_scores import binary_stat_scores, multiclass_stat_scores, multilabel_stat_scores
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index, remove_ignore_index
label_desc: Use image node_id 3 for calling a global function with example usage: _sklearn_stat_scores_multiclass_local(preds, target, ignore_index, average) and returns: np