# libpysal.weights.w_symmetric_difference

libpysal.weights.w_symmetric_difference(w1, w2, w_shape='all', constrained=True, **kwargs)

  Returns a binary weights object, w, that includes only neighbor pairs that are not shared by w1 and w2. The w_shape and constrained parameters determine which pairs that are not shared by w1 and w2 are returned.

  Parameters:
    w1 `W`

      object

    w2 `W`

      object

    w_shape `python:str`

      Defines the shape of the returned weights matrix. ‘all’ returns a matrix with all the unique IDs from w1 and w2; and ‘min’ returns a matrix with the IDs not shared by w1 and w2.

    constrained bool

      If False then the full set of neighbor pairs that are not shared by w1 and w2 are returned. If True then those pairs that would not be possible if w_shape=’min’ are dropped. Ignored if w_shape is set to ‘min’.

    **kwargs `keyword` `arguments`

      optional arguments for `pysal.weights.W`

  Returns:
    w `W`

      object

  Notes

  ID comparisons are performed using ==, therefore the integer ID 2 is equivalent to the float ID 2.0.

  Examples

  Construct queen weights matrix for a 4x4 (16 areas) region (w1) and a rook matrix for a 6x4 (24 areas) region (w2). The symmetric difference of these two matrices (with w_shape set to ‘all’ and constrained set to False) contains the corner joins in the overlap area, all the joins in the non-overlap area.

      >>> from libpysal.weights import lat2W, w_symmetric_difference
      >>> w1 = lat2W(4,4,rook=False)
      >>> w2 = lat2W(6,4,rook=True)
      >>> w = w_symmetric_difference(w1, w2, constrained=False)
      >>> w1[0] == w[0]
      False
      >>> w1.neighbors[15]
      [10, 11, 14]
      >>> w2.neighbors[15]
      [11, 14, 19]
      >>> set(w.neighbors[15]) == set([10, 19])
      True