扩展三维阵列

2024-09-28 03:12:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个形状为200130131(x,y,z)的三维数组。基本上就是屏蔽文件。我们可以说它被称为“maskCoords”。我想把它扩展到我原来的数据形状512*512*485(x,y,z)。但保持掩码不变,并将其余索引填充为零。你知道吗

所以,我创建了一个空的3D数组,比如:

 mask3d = np.zeros_like(MainData3d)

但现在我无法理解如何用保存在屏蔽文件中的值填充这个mask3d数组。我试着做我喜欢的事

mask3d[maskCoords]=1

但事实并非如此工作。什么时候I重叠Maindata3d和mask3d遮罩区域不可见。 任何帮助或想法都将不胜感激。你知道吗


Tags: 文件数据区域npzeros数组事实like
1条回答
网友
1楼 · 发布于 2024-09-28 03:12:55

我假设你的maskCoords是3d坐标到你的3d数组中,我的答案是,因为就像你问题中的评论所说的,很难准确地说出你的意思。你知道吗

这是方法。你知道吗

mask3d = np.zeros((512, 512, 485))

# Create random coordinates
maskCoords = (np.random.random((200, 130, 131)) * 400).astype('int')

# Convert the coordinates to be converted by numpy.ravel_multi_index
maskCoords2 = np.hstack((maskCoords[:, :, 0].flatten()[:, None], maskCoords[:, :, 1].flatten()[:, None], maskCoords[:, :, 2].flatten()[:, None])).T

# Convert the coordinates into indices so we can access the locations in the original array
inds = np.ravel_multi_index(maskCoords2, [512, 512, 485])

# Set the array values at the locations of the indices to 1
mask3d.flat[inds] = 1

也许不是你想要的,但我还是在尝试。你知道吗

相关问题 更多 >

    热门问题