三个2D轮廓到3D阵列 [英] Three 2d profiles to 3d array
问题描述
在numpy中是否有可用的放样方法将三个2d轮廓转换为3d数组?其中x是直视视图,y是水平视图,z是鸟瞰视图.因此,如果在3d空间中x,y和z中的每个值都等于1,则保持值1,否则给出值0.因此,在这个小例子中,我应该相信有108个唯一值(9 * 12) ...
Is there a staking method available within numpy to convert three 2d profiles into a 3d array? Where x is the straight on view, y is the horizontal view and z is the birds eye view. Whereby if in a 3d space each value in the x,y and z are all equal to 1 maintain the value of 1 otherwise give a value of 0. So in this small example there should be 108 unique values I believe (9*12)...
import numpy as np
x = np.array([[1, 1, 1],
[0, 1, 1],
[0, 1, 1]])
y = np.array([[1, 1, 1],
[ 1, 1, 1],
[ 0, 1, 1],
[ 0, 0, 1]])
z = np.array([[0, 1, 1],
[ 0, 1, 1],
[ 0, 0, 1],
[ 0, 0, 0]])
即如果我们从[0, 0]
的x
数组开始,值是1
,在位置y[0,0]
处的值也是1
,但是在z[0, 0]
处的值也是0
,因此[0,0,0]
处应为0
.使用相同的位置x
和y
,但将z
更改为位置z[0, 1]
也是1
的值,因此位置[0, 0, 1]
的xyz
3d数组应为1
.因此,应该从本质上讲是创建矩形3D网格的许多排列.
i.e. if we start from the x
array at [0, 0]
the value is 1
, at position y[0,0]
the value is also 1
however at z[0, 0]
the value is 0
so the 3d array of xyz
should be 0
at [0,0,0]
. Using the same positions of x
and y
but changing z
to position z[0, 1]
is a value of 1
as well so the xyz
3d array at location [0, 0, 1]
should be 1
. So it should be a number of permutations essentially creating a rectangular 3D grid.
推荐答案
您可以结合广播和按位/逻辑运算来做到这一点:
You can combine broadcasting and bitwise/logical operations to do this:
>>> x[np.newaxis, :, :] & y[:, np.newaxis, :] & z[:, :, np.newaxis]
array([[[0, 0, 0],
[0, 1, 1],
[0, 1, 1]],
[[0, 0, 0],
[0, 1, 1],
[0, 1, 1]],
[[0, 0, 0],
[0, 0, 0],
[0, 1, 1]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]])
>>>
这篇关于三个2D轮廓到3D阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!