1

I used FeatureClassToNumPyArray like this:

arcpy.MakeFeatureLayer_management(datapath, "lyr_fixpoints", "area_in_m2 > 8000") 
arr = arcpy.da.FeatureClassToNumPyArray("lyr_fixpoints", ('land_type', 'asset_cat', 'name', 'maintenance'), null_value=-999)  
print arr

and get the following 1d array:

[(5, 0, 380, 3) (1, 4, 369, 3) (5, 0, 421, 2) (0, 7, 425, 1)]

Now I want to convert this array into a 2d array of this form, because the 2d array is very suitable for my further operations.

[[5 0 380 3]
 [1 4 369 3]
 [5 0 421 2]
 [0 7 425 1]]

Can someone help me?

1
  • 1
    Now that you have an array you seem to be using pure Python so have you searched for your answer at Stack Overflow?
    – PolyGeo
    Nov 24, 2017 at 20:20

1 Answer 1

1

I can't specifically comment on ArcPy, as I have never used it. However it seems that you already have a 2-D numpy array with a shape of 4x4 (4 rows and 4 columns):

import numpy as np

Array2D = np.array([(5, 0, 380, 3), (1, 4, 369, 3), (5, 0, 421, 2), (0, 7, 425, 1)])
print(Array2D)
print("Array shape =", Array2D.shape)
print("Dimensions =", Array2D.ndim)

Array1D = Array2D.flatten() # Flatten to a 1D array
print(Array1D)
print("Array shape =", Array1D.shape)
print("Dimensions =", Array1D.ndim)

The 2D array: Array shape = (4, 4); Dimensions = 2.

The 1D array: Array shape = (16, ); Dimensions = 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.