简体   繁体   中英

Why can I not reproduce a nd array manually?

I'm confused about these data structures.

From a GIS system, I use a function to extract the meta data (8 different fields)

myList = FeatureClassToNumPyArray(...)
myList = [('a', 'b', 'c'...) ('aa', 'bb', 'cc'...) ..]    # 8 fields
print (type(myList ))
print (myList.shape)
print (myList.size)

This produces:

<class 'numpy.ndarray'>
(1, 9893)
9893

# I was expecting to get (9893 rows x 8 cols), as in (8,9893)   
# or (9893, 8), but anyway, let's not worry about that right now. 

So I try this:

>>> source = [('a', 'b', 'c') ('aa', 'bb', 'cc')]

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object is not callable

But throw in a comma separator, and it's fine... but now it's a list.

>>> source = [('a', 'b', 'c'), ('aa', 'bb', 'cc')]
>>> type(source)
<class 'list'>

So, this magical GIS function can produce a data structure that is accepted as a numpy data array, but if I try create it manually, it's not possible.

What am I missing?

Not sure how to do this, but the comment by juanpa.arrivillaga should be marked as the answer.

Again, why do you expect print(something) to produce a string that is valid python source code to produce that object? That is your fundamental assumption that is wrong. That is what you are missing. print(repr(something)) will often get you something much closer, but it is never guaranteed to be valid source code. Again, likely it returns a numpy.ndarray with some structured dtype. What is myList.dtype? EDIT: so a very basic example, something = object(); print(something) now try to reproduce that from the string representation... there's no reason to expect to be able to. – juanpa.arrivillaga May 13 at 21:18

My question originates from a fundamental misunderstanding of what a dataframe is and how it works. Took me while to work it out.

In my words, it's an object that needs to be manipulated through various tools/functions... it's not just a matrix of "strings".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM