我正在try 对点云麻木数组进行动态切片.切片将过滤x/y坐标落入由minx
、miny
、maxx
、maxy
定义的边界列表内的点
我以为我有一个有效的算法,但我面对的是The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
例如(这只是演示数据):
import numpy as np
bounds_list = [
(0, 0, 5, 5),
(8, 8, 10, 10)
]
#col0 --> x , col1 --> y , col2 --> z
random_arr = np.array([10, 10, 100]) * np.random.rand(100, 3)
def filter_by_bounds(arr):
slices = np.array([np.array([bounds[0] <= arr[0] <= bounds[2], bounds[1] <= arr[1] <= bounds[3]]).all() for bounds in bounds_list]).any()
return arr[slices]
filtered_arr = filter_by_bounds(random_arr)
print(filtered_arr)
在此演示中,我希望检索其x/y坐标至少在一个界限内的所有点