如果我理解正确,您希望在 3 个维度中的每个维度中对数组的每个 (2^n):th 值进行采样。
您可以通过如下索引来做到这一点。
>>> import numpy as np
>>> n = 1
>>> example_array = np.zeros((1024,1024,1024))
>>> N = 2^n
>>> example_array_sampled = example_array[::N, ::N, ::N]
>>> example_array_sampled.shape
(512, 512, 512)
验证它实际上是否均匀采样:
>>> np.arange(64).reshape((4,4,4))[::2,::2,::2]
array([[[ 0, 2],
[ 8, 10]],
[[32, 34],
[40, 42]]])
此特定代码仍假定您将在对它进行索引之前读取内存中的整个数组。而变量example_array_sampled 将是原始数组的视图。
有关索引 numpy 数组的更多信息:https://numpy.org/doc/stable/reference/arrays.indexing.html
关于 numpy 视图的一些信息:https://scipy-cookbook.readthedocs.io/items/ViewsVsCopies.html
相关问题(一维):subsampling every nth entry in a numpy array