AnsweredAssumed Answered

Creating an numpy array from a list for using with NumPyArrayToTable

Question asked by jjr@therogers.com.au on Oct 26, 2014
Latest reply on Nov 16, 2014 by Dan_Patterson

I am attempting to put a 2-dimensional list of data into a numpy array for use with NumPyArrayToTable.  If I create a array of strings like this:

 

inarray = numpy.array( [ ('Route.mxd', 'False', 'Emirates_Route', 'route.shp', '0.0')

('Route.mxd', 'False', 'World Cities', 'cities', '50.0')

('Updated.mxd', 'True', 'Meter1', 'Meter1', '0.0')

('Updated.mxd', 'True', 'Meter1', 'Meter1', '0.0')],numpy.dtype(dts))

 

Then it converts perfectly into a numpy.array and then to an ArcGIS Table. The data-type string works perfectly:

[('Map', '|S45'), ('RelativePath', '|S5'), ('LayerName', '|S35'), ('LayerFile', '|S85'), ('Scale', '|S15')]

 

However when I create an list via looping and appending the strings in python (code below), I end up with an list/array like this:

[ ['Route.mxd', 'False', 'Emirates_Route', 'route.shp', '0.0'],

['Route.mxd', 'False', 'World Cities', 'cities', '50.0'],

['Updated.mxd', 'True', 'Meter1', 'Meter1', '0.0'],

['Updated.mxd', 'True', 'Meter1', 'Meter1', '0.0']]

 

This converts to a numpy.array with no problems, but when I use NumPyArrayToTable, it creates the 5 columns correctly, but puts all the data in the first column as:

Route.mxd

False

Emirates_Route

route.shp

0.0

Route.mxd

False

World Cities...

 

I can see that these two data structures are being handled differently by numpy, however I don't know how to get the second into the same format as the first, which works perfectly.  I have tried using asarray to convert the list to an array but this appears to duplicate everything and still leaves the square brackets.

 

(I realise that numpy is not really meant for strings, but I am trying to code using it and this is just a theoretical exercise.)

 

MyList.append([])                                              MyList[count].append(mapDoc.encode('UTF8'))                         MyList[count].append(relPaths.encode('UTF8'))                         MyList[count].append(lyrTitle.encode('UTF8'))                        MyList[count].append(sourceTitle.encode('UTF8'))                         MyList[count].append(theScale.encode('UTF8'))

Outcomes