# Getting matrix from polygon attribute table that represents vertex couples using ArcGIS Desktop?

How can I get a matrix from a polygon attribute table that represents polygon vertex couples?

What I want is something like this :

A = [ (A1,B1) , (A1,C1) , (B1,C1) (A2,B2) , (A2,C2) , (B2,C2) .... , .... , .... ... , .... , .... ] ]

• How/where do you want the results? As a list of lists?
– Bera
Commented Sep 7, 2018 at 17:16
• Welcome to GIS SE! As a new user be sure to take the Tour to learn about our focussed Q&A format.
– PolyGeo
Commented Sep 14, 2018 at 6:29

If I understand you correctly something similar to below may help.

I created two new fields, Fields_1_2 and Fields_1_3, both of which are text data types. I then ran the following Python script in the Field Calculator on the Fields_1_2 field:

str(!Field1!) + ", " + str(!Field2!)


And the following Python script on the Fields_1_3 field:

str(!Field1!) + ", " + str(!Field3!)


The results looks like this:

Use the da.SearchCursor and itertools.combinations:

Return r length subsequences of elements from the input iterable.

combinations('ABCD', 2) --> AB AC AD BC BD CD

import arcpy
from itertools import combinations

feature_class = r'C:\data.gdb\featureclass'
fields = ['POINT A', 'POINT B', 'POINT C']

all_combinations = []

with arcpy.da.SearchCursor(feature_class,fields) as cursor:
for row in cursor:
all_combinations.append(list(combinations(row,2)))


Will give you:

>>all_combinations
[[(1, 2), (1, 5), (2, 5)],
[(43, 4), (43, 6), (4, 6)]
...]

• @baccaribilel nice, could you accept my answer with the checkbox?
– Bera
Commented Sep 8, 2018 at 6:10