简体   繁体   English

将 numpy 数组写入为 VTK 文件

[英]Writing numpy array as VTK file

I have a 2D numpy array that I wish to export and write as a VTK file.我有一个 2D numpy 数组,我希望将其导出并写入为 VTK 文件。 I have tried the vtk package as well as PyEVTK package but am running into issues with both.我已经尝试过 vtk 包和 PyEVTK 包,但都遇到了问题。

Thanks.谢谢。

I believe this is what you're looking for:我相信这就是你要找的:

from vtk.util import numpy_support
numpy_to_vtk(num_array, deep=0, array_type=None)

Is this what you asking for?这是你要求的吗? It is easy to use but you have to know the connectivity of yourElements它易于使用,但您必须了解您的元素的连接性

import meshio 

yourNodes = np.array([...])
yourElements = np.array([...])
cells = [("triangle", yourElements )]
mesh = meshio.Mesh(yourNodes , cells )
mesh.write("foo.vtk")

yourElements start at 0 and not at 1! yourElements 从 0 开始而不是从 1 开始!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM