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

问题描述 投票:0回答:1

我对这些数据结构感到困惑。

从GIS系统中,我使用一个函数来提取元数据(8个不同的字段)

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

这将产生:

<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. 

所以我试试这个:

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

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

但是放入逗号分隔符,这很好...但是现在是列表。

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

因此,这个神奇的GIS函数可以产生一个被接受为numpy数据数组的数据结构,但是如果我尝试手动创建它,那是不可能的。

我想念什么?

python numpy-ndarray
1个回答
0
投票

[不确定如何执行,但是juanpa.arrivillaga的评论应标记为答案。

同样,为什么还要期望print(something)生成一个字符串,该字符串是有效的python源代码才能生成该对象?那是您错误的基本假设。那就是你所缺少的。 print(repr(something))通常会使您更加接近,但是永远不能保证它是有效的源代码。同样,它可能返回带有某些结构化dtype的numpy.ndarray。什么是myList.dtype?编辑:所以一个非常基本的示例,= = object();现在,print(something)尝试从字符串表示形式中重现该信息……没有理由期望能够这样做。 – juanpa.arrivillaga,5月13日,21:18

我的问题源自对数据帧是什么以及它如何工作的基本误解。花了我一些时间解决。

用我的话说,这是一个需要通过各种工具/功能进行操作的对象……它不仅仅是“字符串”的矩阵。

© www.soinside.com 2019 - 2024. All rights reserved.