小编Bar*_*ssa的帖子

如何通过索引列表过滤numpy数组?

我是python的新手,并一直在努力学习如何使用numpy和scipy.我有一个由LAS数据[x,y,z,强度,分类]组成的numpy数组.我创建了一个cKDTree点,并使用query_ball_point找到了最近的邻居.我想找到query_ball_point返回的邻居的z值的标准偏差,它返回该点及其邻居的索引列表.

有没有办法过滤filtered__rows来创建一个只有点的数组,其索引在query_ball_point返回的列表中?见下面的代码.我可以将值附加到列表并从中计算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 …
Run Code Online (Sandbox Code Playgroud)

python numpy nearest-neighbor scipy lidar

8
推荐指数
4
解决办法
2万
查看次数

如何根据另一列替换numpy数组中的值?

假设我有以下内容:

import numpy as np

data = np.array([
     [1,2,3],
     [1,2,3],
     [1,2,3],
     [4,5,6],         
     ])
Run Code Online (Sandbox Code Playgroud)

我如何根据第2列中的值更改第3列中的值?例如,如果第3列== 3,则第2列= 9.

[[1,9,3],
 [1,9,3],
 [1,9,3],
 [4,5,6]]
Run Code Online (Sandbox Code Playgroud)

我看过了np.any(),但我无法弄清楚如何改变阵列.

python arrays numpy

8
推荐指数
1
解决办法
9106
查看次数

如何估算3d点的局部切平面?

假设我有一组积分,

R = [[x1, y1, z1],[x2, y2, z2],...,[xn, yn, zn]]
Run Code Online (Sandbox Code Playgroud)

对于R中的每个点(p),我使用scipy.cKDTree确定了半径(r)和高度(2r)的局部邻域.

import numpy as np
import scipy.spatial

R = np.array(R)
r = 1 # search radius

xy = R[:,0:2] # make array of ONLY xy
tree = scipy.spatial.cKDTree(xy)

for p in range(len(R)):
    2d_nbr_indices = tree.query_ball_point(xy[p], r) # indices w/in xy neighborhood
    2d_nbr_array = R[2d_nbr_indices] # 3d array of 2d neighbors
    z = R[p][1] # get z value
    zMin = z - r
    zMax = z + r
    # Create boolean …
Run Code Online (Sandbox Code Playgroud)

python regression numpy scipy point-clouds

6
推荐指数
1
解决办法
1816
查看次数

python 内存不足错误的解决方法是什么?

我正在将 ax,y,z 点文件 (LAS) 读入 python 并遇到内存错误。我正在为我正在处理的项目在已知点之间插入未知点。我开始处理小文件(< 5,000,000 点)并且能够毫无问题地读/写 numpy 数组和 python 列表。我收到了更多要使用的数据(> 50,000,000 点),现在我的代码因 MemoryError 而失败。

处理如此大量的数据有哪些选择?我不必一次将所有数据加载到内存中,但我需要使用scipy kd-tree查看相邻点我在 64 位 Windows XP 操作系统上使用 Python 2.7 32 位。

提前致谢。

编辑:代码发布在下面。我拿出了长计算和变量定义的代码。

from liblas import file
import numpy as np

f = file.File(las_file, mode='r')
num_points = int(f.__len__())
dt = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('i', 'u2'), ('c', 'u1'), ('t', 'datetime64[us]')]
xyzict = np.empty(shape=(num_points,), dtype = dt)
counter = 0
for p in f:
    newrow = (p.x, p.y, p.z, p.intensity, …
Run Code Online (Sandbox Code Playgroud)

python numpy out-of-memory scipy

4
推荐指数
1
解决办法
2万
查看次数