简体   繁体   English

为什么我不能手动复制 nd 数组?

[英]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.

相关问题 为什么我收到 numpy.nd 数组的属性错误? - why i am getting an attribute error for numpy.nd array? 如何循环播放歌曲? - How can I reproduce a song on loop? 如何重现 statsmodels ARIMA 过滤器? - How can I reproduce the statsmodels ARIMA filter? 我可以使用列表理解在 python 的二维数组中获取输入吗?? 以及如何为 nD 数组实现它? - Can I Use the List Comprehensions for taking input in the 2D Array in the python ??. And how it can be implemented for the nD array? statsmodels为什么不能重现我的R logistic回归结果? - Why can't statsmodels reproduce my R logistic regression results? 如何沿着nD数组的轴选择具有该轴的(n-1)D索引数组的值? - How can I select values along an axis of an nD array with an (n-1)D array of indices of that axis? 为什么我无法使用gensim复制word2vec结果 - Why I cannot reproduce word2vec results using gensim 如何在 matlab 和 python 中重现相同的随机 integer 数组? - How do I reproduce the same random integer array in matlab and python? 如何可靠地重现此python代码中的竞争条件? - How can I reproduce the race conditions in this python code reliably? Python的一个奇怪函数的结果,我无法用其他语言复制 - Python result of a strange function, that I can't reproduce in another language
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM