Skip to main content
`Ctrl`+`K`
scipy.spatial.distance.

# dice

scipy.spatial.distance.dice(u, v, w=None)

  Compute the Dice dissimilarity between two boolean 1-D arrays.

  The Dice dissimilarity between u and v, is

  \[\frac{c_{TF} + c_{FT}} {2c_{TT} + c_{FT} + c_{TF}}\]

  where \(c_{ij}\) is the number of occurrences of \(\mathtt{u[k]} = i\) and \(\mathtt{v[k]} = j\) for \(k < n\).

  Parameters:
    u(N,) array_like, bool

      Input 1-D array.

    v(N,) array_like, bool

      Input 1-D array.

    w(N,) array_like, optional

      The weights for each value in u and v. Default is None, which gives each value a weight of 1.0

  Returns:
    dicedouble

      The Dice dissimilarity between 1-D arrays u and v.

  Notes

  This function computes the Dice dissimilarity index. To compute the Dice similarity index, convert one to the other with similarity = 1 - dissimilarity.

  Examples

      >>> from scipy.spatial import distance
      >>> distance.dice([1, 0, 0], [0, 1, 0])
      1.0
      >>> distance.dice([1, 0, 0], [1, 1, 0])
      0.3333333333333333
      >>> distance.dice([1, 0, 0], [2, 0, 0])
      -0.3333333333333333