pysal.lib.weights.full2W

pysal.lib.weights.full2W(m, ids=None)[source]

Create a PySAL W object from a full array.

Parameters:
m : array

nxn array with the full weights matrix

ids : list

User ids assumed to be aligned with m

Returns:
w : W

PySAL weights object

Examples

>>> import pysal.lib
>>> import numpy as np

Create an array of zeros

>>> a = np.zeros((4, 4))

For loop to fill it with random numbers

>>> for i in range(len(a)):
...     for j in range(len(a[i])):
...         if i!=j:
...             a[i, j] = np.random.random(1)

Create W object

>>> w = pysal.lib.weights.util.full2W(a)
>>> w.full()[0] == a
array([[ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True]])

Create list of user ids

>>> ids = ['myID0', 'myID1', 'myID2', 'myID3']
>>> w = pysal.lib.weights.util.full2W(a, ids=ids)
>>> w.full()[0] == a
array([[ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True],
       [ True,  True,  True,  True]])