[英]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)从 GIS 系统中,我使用 function 来提取元数据(8 个不同的字段)
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.所以,这个神奇的 GIS function 可以生成一个被接受为 numpy 数据数组的数据结构,但如果我尝试手动创建它,这是不可能的。
What am I missing?我错过了什么?
Not sure how to do this, but the comment by juanpa.arrivillaga should be marked as the answer.不知道该怎么做,但是 juanpa.arrivillaga 的评论应该被标记为答案。
Again, why do you expect print(something) to produce a string that is valid python source code to produce that object?同样,为什么您希望 print(something) 生成一个有效的 python 源代码的字符串来生成 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. print(repr(something)) 通常会让你更接近一些东西,但它永远不能保证是有效的源代码。 Again, likely it returns a numpy.ndarray with some structured dtype.同样,它可能会返回一个带有一些结构化 dtype 的 numpy.ndarray。 What is myList.dtype?什么是 myList.dtype? EDIT: so a very basic example, something = object();编辑:这是一个非常基本的例子,something = object(); print(something) now try to reproduce that from the string representation... there's no reason to expect to be able to. print(something) 现在尝试从字符串表示中重现它......没有理由期望能够做到。 – juanpa.arrivillaga May 13 at 21:18 – juanpa.arrivillaga 5 月 13 日 21:18
My question originates from a fundamental misunderstanding of what a dataframe is and how it works.我的问题源于对 dataframe 是什么以及它如何工作的根本误解。 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".用我的话来说,它是一个 object,需要通过各种工具/功能进行操作……它不仅仅是一个“字符串”矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.