3D array using data from existing lists

点点圈 提交于 2021-02-08 11:38:42

问题


I am new to python and am having trouble with multi-dimensional arrays. I have a list(s) of points in 3-dimensions(x,y,z) that I am trying to use in marching_cubes_lewiner(). The co-ordinate values are in 3 lists: x,y and z such that any point will be given by (x[i],y[i],z[i]).

Now, marching_cubes_lewiner() accepts volume as a 3D numpy array. What would be the best way to convert the 3 lists into a 3D numpy array?

I have tried:

s=len(x)
points = np.ndarray((s,s,s),buffer=np.array([x,y,z]), dtype=float)

but am getting the following error: buffer is too small for requested array. Any pointers would be much appreciated.

Edit: I apologize for the question not not being very clear. The co-ordinates of all points are in this text file in the format "x y z".

Reg. the output: I would like to get a 3D numpy array that would be compatible with(be the input of) the marching cubes function provided here. To clarify, the output would be the 'volume' of the function above. I apologize again for the wording of this problem not being coherent.

Here is the error I am currently getting:

TypeError                                 Traceback (most recent call last)
<ipython-input-80-3be08f942830> in <module>
      9 
     10 s=len(x)
---> 11 t = np.ndarray((s,s,s),buffer=np.array([x,y,z]), dtype=float)

TypeError: buffer is too small for requested array

来源:https://stackoverflow.com/questions/60310925/3d-array-using-data-from-existing-lists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!