1

I have used the FeatureClassToNumPyArray tool in ArcPy, but the numpy array that is imported has only rows, with each of the fields in the original feature class as numpy.void type.

Here is a reproducible array.

b = np.array([(0,1),(1,1.5),(2,1.25),(3,1.28)],dtype=[('FID','<i4'),('Value','<f4')])

this returns a (4,) array, I want to reshape so that the array is (4,2) with the names 'FID' and 'Value', but can't quite figure out how to do this 'elegantly'.

I know that I can extract 'FID' and 'Value' as lists and then combine using np.array, but is that the best way to do it?

arr = np.array([b['FID'],b['Value']]).T
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Aug 19, 2020 at 19:57
1
  • I believe you can use numpy.lib.recfunctions.structured_to_unstructured, but note that when creating an unstructured array all of your values will be cast to the same dtype, float32 in this case. This is true for your example using transpose above, as well. Commented Aug 20, 2020 at 17:08

1 Answer 1

1

So I am not sure how to do it with numpy only, but if you issue the following, it works.

import pandas as pd
df = pd.DataFrame(data=arr.flatten())

If there is a better way, let me know.

answered Aug 20, 2020 at 15:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.