首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对laspy创建的numpy数组进行排序

对laspy创建的numpy数组进行排序
EN

Stack Overflow用户
提问于 2017-10-20 07:26:15
回答 2查看 934关注 0票数 1

我知道这听起来像一个简单的问题,一个简单的解决方案,但我就是不能把我的头围绕在它上面。

laspy的文档有点稀疏,但到目前为止我管理得很好。我认为,现在的问题是对“矮胖”不太熟悉。

我想要根据GPS时间来排序一个numpy数组.

我的立场如下:

我正在使用laspy附带的sample.las进行测试。

代码语言:javascript
运行
复制
import laspy
import numpy as np

#open the file
lasFile = laspy.file.File("C:/Anaconda3/Lib/site-packages/laspytest/data/simple.las", mode = "rw") 

#put points in numpy array
lasPoints = lasFile.points

我要做的是按照gps_time列对数组进行排序。

代码语言:javascript
运行
复制
print(lasPoints.dtype)

给我

代码语言:javascript
运行
复制
[('point', [('X', '<i4'), ('Y', '<i4'), ('Z', '<i4'), ('intensity', '<u2'), ('flag_byte', 'u1'), ('raw_classification', 'u1'), ('scan_angle_rank', 'i1'), ('user_data', 'u1'), ('pt_src_id', '<u2'), ('gps_time', '<f8'), ('red', '<u2'), ('green', '<u2'), ('blue', '<u2')])]

代码语言:javascript
运行
复制
print(lasPoints)

给我

代码语言:javascript
运行
复制
[ ((63701224, 84902831, 43166, 143, 73, 1,  -9, 132, 7326,  245380.78254963,  68,  77,  88),)
 ((63689633, 84908770, 44639,  18, 81, 1, -11, 128, 7326,  245381.45279924,  54,  66,  68),)
 ((63678474, 84910666, 42671, 118,  9, 1, -10, 122, 7326,  245382.13595007, 112,  97, 114),)
 ...,
 ((63750167, 85337575, 41752,  43,  9, 1,  11, 124, 7334,  249772.21013494, 100,  96, 120),)
 ((63743327, 85323084, 42408,  31,  9, 1,  11, 125, 7334,  249772.70733372, 176, 138, 164),)
 ((63734285, 85324032, 42392, 116, 73, 1,   9, 124, 7334,  249773.20172407, 138, 107, 136),)]

要访问我可以运行的gps_time

代码语言:javascript
运行
复制
lasPoints[0][0][9] ## first gps_time in array
lasPoints[1][0][9] ## second gps_time in array

将"gps_time“替换为9会产生相同的结果。

现在,当我试图对我的数据进行排序时,它似乎并没有对任何内容进行排序:

代码语言:javascript
运行
复制
np.sort(lasPoints["point"]["gps_time"])
print(lasPoints)

数组被打印出来,没有排序,

代码语言:javascript
运行
复制
lasPoints=np.sort(lasPoints["point"]["gps_time"])
print(lasPoints)

结果将gps_time按如下方式排序:

代码语言:javascript
运行
复制
[ 245370.41706456  245370.74331403  245371.06452222 ...,  249782.07498673
  249782.64531958  249783.16215837]

我哪里出问题了?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-20 07:37:49

就我所理解的文档而言,np.sort似乎不支持内部排序。然而,np.ndarray.sort确实如此。所以

代码语言:javascript
运行
复制
np.sort(lasPoints["point"]["gps_time"])
print(lasPoints)

永远不会被整理好。

但对于您的问题:您可以将GPS时间列表从列表中分割出来,并使用argsort获取排序列表的索引。这些可以用来分类你的套索。例如:

代码语言:javascript
运行
复制
sorted_ind = np.argsort(list_of_gpstimes)
laspoints = laspoints[sorted_ind]
票数 2
EN

Stack Overflow用户

发布于 2017-10-20 08:24:02

为了完全结束这个问题,并在dudakl的回答的基础上,使用np.ndarray进行排序,这对我来说是有效的:

代码语言:javascript
运行
复制
np.ndarray.sort(lasPoints["point"],kind='mergesort',order='gps_time')

这里的关键是指定lasPoint“点”,然后通过gps_time进行排序。

这里只对gps_time颜色进行排序,而没有其他颜色。

代码语言:javascript
运行
复制
np.ndarray.sort(lasPoints["point"]["gps_time]) 
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46844233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档