从3D数组转换为X,Y,Z和标量S

时间:2017-10-09 08:52:37

标签: python

我想从3D数组转换为X,Y,Z和标量S.

假设我有一个100x100x100的3d数组,采样率为1.因此X = 100,等等..

每个3D点都包含一个标量值。

在: 3D矩阵A

在: X,Y,Z,S

如何从3D数组转换为XYZ和python中的标量。

1 个答案:

答案 0 :(得分:0)

当你在开头有3个尺寸时,我无法理解为什么你想要4个输出。如果您的3D数组只包含S的值,那么您的坐标只是由索引定义?

如果是这样,你需要重塑你的3D阵列(重塑)https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html

   A=np.zeros((2,3,4)) # I initialize it for me
   A.shape             # I get its shape
   B=A.reshape( A.shape[0]*A.shape[1]*A.shape[2],1) # B is now the same in 1D array

现在你必须找到一种方法来根据1D数组中的索引获取坐标。你可以很容易地做到这一点,你只需要知道重塑的顺序是什么。像itertool这样的工具可能会成功!

    C=list(itertools.product(range(A.shape[0]),range(A.shape[1]),range(A.shape[2])))
   # Each element of coordinate are the three coordinates of the point. You can split it if you want

也许从小于100x100x100的东西开始,它很难检查它是否真的有用

相关问题