# libpysal.weights.block_weights

libpysal.weights.block_weights(regimes, ids=None, sparse=False, **kwargs)

  Construct spatial weights for regime neighbors.

  Block contiguity structures are relevant when defining neighbor relations based on membership in a regime. For example, all counties belonging to the same state could be defined as neighbors, in an analysis of all counties in the US.

  Parameters:
    regimes `python:list`, `array`

      ids of which regime an observation belongs to

    ids `python:list`, `array`

      Ordered sequence of IDs for the observations

    sparse bool

      If True return WSP instance If False return W instance

    **kwargs `keyword` `arguments`

      optional arguments for `pysal.weights.W`

  Returns:
    W `spatial` `weights` `instance`

  Examples

      >>> from libpysal.weights import block_weights
      >>> import numpy as np
      >>> regimes = np.ones(25)
      >>> regimes[range(10,20)] = 2
      >>> regimes[range(21,25)] = 3
      >>> regimes
      array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 2., 2., 2., 2., 2., 2., 2.,
             2., 2., 2., 1., 3., 3., 3., 3.])
      >>> w = block_weights(regimes)
      >>> w.weights[0]
      [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
      >>> w.neighbors[0]
      [1, 2, 3, 4, 5, 6, 7, 8, 9, 20]
      >>> regimes = ['n','n','s','s','e','e','w','w','e']
      >>> n = len(regimes)
      >>> w = block_weights(regimes)
      >>> w.neighbors == {0: [1], 1: [0], 2: [3], 3: [2], 4: [5, 8], 5: [4, 8], 6: [7], 7: [6], 8: [4, 5]}
      True