code: def _np_dunn_index(data, labels, p):
      unique_labels, inverse_indices = np.unique(
          labels, return_inverse=True
      )
      clusters = [
          data[inverse_indices == label_idx]
          for label_idx in range(len(unique_labels))
      ]
      centroids = [c.mean(axis=0) for c in clusters]
  
      intercluster_distance = np.linalg.norm(
          np.stack(
              [a - b for a, b in combinations(centroids, 2)], axis=0
          ),
          ord=p,
          axis=1,
      )
  
      max_intracluster_distance = np.stack(
          [
              np.linalg.norm(ci - mu, ord=p, axis=1).max()
              for ci, mu in zip(clusters, centroids)
          ]
      )
  
      return (
          intercluster_distance.min() / max_intracluster_distance.max()
      )
  
file_path: torchmetrics/tests/unittests/clustering/test_dunn_index.py
imports: from functools import partial
  from itertools import combinations
  import numpy
  import pytest
  from torchmetrics.clustering.dunn_index import DunnIndex
  from torchmetrics.functional.clustering.dunn_index import dunn_index
  from unittests.clustering.inputs import _single_target_intrinsic1, _single_target_intrinsic2
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 1 for calling a global function with example usage: _np_dunn_index(data, labels, p) and returns: unknown