[英]How can I export data from Python to .txt?
I am a new Python user and I have a question regarding exporting data from Python.我是一个新的 Python 用户,我有一个关于从 Python 导出数据的问题。 I wrote a code to create a mesh using Delaunay triangulation.我编写了一个代码来使用 Delaunay 三角剖分创建网格。 For the triangulation I used matplotlib.tri library.对于三角测量,我使用了 matplotlib.tri 库。 I got a plot of a grid and now I would like to save coordinates of nodes and elements.我得到了一个网格的 plot,现在我想保存节点和元素的坐标。 So I saved list of nodes:所以我保存了节点列表:
#saving data
data = np.array([mesh_x, mesh_y]) #mesh_x and mesh_y - nodes that used in triangulation
data = np.transpose(data)
np.savetxt('nodes_data.txt', data, delimiter = ',')
Now I want to save elements, each of which contains two nodes because I consider truss-elements.现在我想保存元素,每个元素都包含两个节点,因为我考虑桁架元素。 Do you have any suggestions, how can I export elements to.txt file?您有什么建议,我如何将元素导出到 .txt 文件?
My best understanding of your question leads me to this answer我对您的问题的最佳理解使我得到了这个答案
In [7]: import numpy as np
...: from matplotlib.tri import Triangulation
...: np.random.seed(sum(ord(c) for c in 'gboffi'))
...: x, y = [np.random.random(10) for _ in (0,0)]
...: tri = Triangulation(x, y)
...: print(tri.edges)
[[1 0]
[2 1]
[4 0]
[4 1]
[5 0]
[5 1]
[5 2]
[6 0]
[6 3]
[6 4]
[7 3]
[7 4]
[7 6]
[8 1]
[8 2]
[8 4]
[8 7]
[9 0]
[9 3]
[9 6]]
In [8]:
Is this what you want?这是你想要的吗?
PS I have read a hidden comment of yours: Abaqus/CAE has ways better meshing support. PS 我读过你的一个隐藏评论:Abaqus/CAE 有更好的网格支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.