【发布时间】:2015-07-28 22:02:28
【问题描述】:
我继承了一大段代码,作为一个新手并没有掌握它的复杂性。它正在格式化生成的 2x1 数组,作为 matplotlib.LineCollect 的线段传递
coar[t] = na[j]
coart = coar.reshape(-1,1,2)
segments = np.hstack([coart[:-1],coart[1:]])
请更正我的术语: 它正在迭代 1x2 数组 na 并将它们放入“coar”“数组数组”
coar
[[51 50]
[52 50]
[52 49]
[52 48]] <type 'numpy.ndarray'>
reshape(-1,1,2) 中的参数如何使 coar 成为“数组中的数组中的数组”?
coart:
[[[51 50]]
[[52 50]]
[[52 49]]
[[52 48]]] <type 'numpy.ndarray'>
最后,hstack 使用 LineCollect 将点对绘制为线段。它似乎使用 [:-1] 的 -1 列?负列索引?我不明白这一切是如何运作的
[[[51 50]
[52 50]]
[[52 50]
[52 49]]
[[52 49]
[52 48]]] <type 'numpy.ndarray'>
这是怎么回事…… 对这些函数、格式和数据类型的任何启示都会很棒
【问题讨论】:
标签: python arrays numpy indexing formatting