首页 > 解决方案 > 迭代切片数组的计算效果

问题描述

如果我取一个切片的切片......一个numpy数组,我是在创建一个深度嵌套的数据结构吗?

我要问的概述:

data = np.rand(1024)

while more_to_do(data):
     removed_value = select_item(data)
     # use slicing to "remove" a particular value from the array
     data = data[data!=removed_value]

# Another way to ask the question, would be
# does indexing into data after taking
# all of these slices, e.g. calling 

value = data[5]

# take time proportional to the number of iterations 
# through the loop?

实际上下文是在凹壳算法的特定实现中,该算法使用这种切片迭代地从考虑中删除点,因为它们被选为壳的一部分。

标签: pythonnumpy

解决方案


推荐阅读