数组怎么用python筛选_如何按索引列表筛选numpy数组?

我对python比较陌生,一直在努力学习如何使用numpy和scipy。我有一个由LAS数据组成的核阵列[x,y,z,强度,分类]。我创建了一个点的cKDTree,并使用query_ball_point找到了最近的邻居。我想找到查询球点返回的邻居的z值的标准偏差,它返回点及其邻居的索引列表。

是否有方法筛选筛选筛选的行以创建一个仅包含其索引在查询球点返回的列表中的点的数组?见下面的代码。我可以将这些值附加到一个列表中并从中计算std dev,但我认为使用numpy在单个轴上计算std dev会更容易。提前谢谢。# Import modules

from liblas import file

import numpy as np

import scipy.spatial

if __name__=="__main__":

'''Read LAS file and create an array to hold X, Y, Z values'''

# Get file

las_file = r"E:\Testing\kd-tree_testing\LE_K20_clipped.las"

# Read file

f = file.File(las_file, mode='r')

# Get number of points from header

num_points = int(f.__len__())

# Create empty numpy array

PointsXYZIC = np.empty(shape=(num_points, 5))

# Load all LAS points into numpy array

counter = 0

for p in f:

newrow = [p.x, p.y, p.z, p.intensity, p.classification]

PointsXYZIC[counter] = newrow

counter += 1

'''Filter array to include classes 1 and 2'''

# the values to filter against

unclassified = 1

ground = 2

# Create an array of booleans

filter_array = np.any([PointsXYZIC[:, 4] == 1, PointsXYZIC[:, 4] == 2], axis=0)

# Use the booleans to index the original array

filtered_rows = PointsXYZIC[filter_array]

'''Create a KD tree structure and segment the point cloud'''

tree = scipy.spatial.cKDTree(filtered_rows, leafsize=10)

'''For each point in the point cloud use the KD tree to identify nearest neighbors,

with a K radius'''

k = 5 #meters

for pntIndex in range(len(filtered_rows)):

neighbor_list = tree.query_ball_point(filtered_rows[pntIndex], k)

zList = []

for neighbor in neighbor_list:

neighbor_z = filtered_rows[neighbor, 2]

zList.append(neighbor_z)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值