libpysal.weights.full2W

libpysal.weights.full2W(m, ids=None, **kwargs)[source]

Create a PySAL W object from a full array.

Parameters:
marray

nxn array with the full weights matrix

idslist

User ids assumed to be aligned with m

**kwargskeyword arguments

optional arguments for pysal.weights.W

Returns:
wW

PySAL weights object

Examples

>>> from libpysal.weights import full2W
>>> 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 = 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 = 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]])