来自一组不同长度阵列的矩阵

发布于 2025-01-26 07:11:39 字数 1242 浏览 2 评论 0原文

我有一组花键,每个样条线将信息作为数组存储。 每个样条都有X_COORDz_coordfield,但是这些数组的长度,从样条到另一个样条的长度可能会有所不同。

我需要在所有这些花条中形成X和z中的唯一网格,如果field将值与x和z相互作用相关联,如果x和z在x_coord 和z_coord。否则,它关联0

说我有两个花键:

条形线1:

x1 = np.array([1,3,5,6,7])
z1 = np.array([[10,20,30,40,50]])
field1 = np.array([5,7,9,13,15])

spline2:

x2 = np.array([2,4,6])
z2 = np.array([10,20,30])
field2 = np.array([0.3, 0.5, 0.7])

as x_coordz_coord已经具有常数模式,我认为我可以创建一个矩阵删除重复并与每个矩阵关联位置,相关x_coordz_coordfield通过字典。 但是我是堆栈:

x_new = new_array = np.unique(np.concatenate((x1,x2),0))
z_new = new_array = np.unique(np.concatenate((z1,z2),0))
matrix = random(len(z_new), len(x_new), format='dok')
matrix.toarray()

为此,我希望有7列和5行的网格:

row1 [(1,10,5), (2,10,0.3), (3,10,0), (4,10,0), (5,10,0), (6,10,0), (7,10,0)]
row2 [(1,20,0), (2,20,0), (3,20, 7), (4,20,0.5), (5,20,0), (6,20,0), (7,20,0)]
row3 [(1,30,0), (2,30,0), (3,30,0), (4,30,0), (5,30,9), (6,30,0.7), (7,30,0)]
row4...
row5...

I have a set of splines and each spline stores informations as arrays.
Each spline has x_coord, z_coord, field, but the length of these arrays, from a spline to another can be different.

I need to form a unique grid in x and z, from all these splines, that associates the value from field to the x and z intersections, if x and z have matching in x_coord and z_coord. Otherwise it associates 0.

Say that I have two splines:

Spline 1:

x1 = np.array([1,3,5,6,7])
z1 = np.array([[10,20,30,40,50]])
field1 = np.array([5,7,9,13,15])

Spline2 :

x2 = np.array([2,4,6])
z2 = np.array([10,20,30])
field2 = np.array([0.3, 0.5, 0.7])

As x_coord and z_coord already have a constant pattern, I thought I could create a matrix removing repetitions and associating to each matrix position, relevant x_coord, z_coord and field via dictionary.
But I am stack:

x_new = new_array = np.unique(np.concatenate((x1,x2),0))
z_new = new_array = np.unique(np.concatenate((z1,z2),0))
matrix = random(len(z_new), len(x_new), format='dok')
matrix.toarray()

For that I would expect a grid with 7 columns and 5 rows:

row1 [(1,10,5), (2,10,0.3), (3,10,0), (4,10,0), (5,10,0), (6,10,0), (7,10,0)]
row2 [(1,20,0), (2,20,0), (3,20, 7), (4,20,0.5), (5,20,0), (6,20,0), (7,20,0)]
row3 [(1,30,0), (2,30,0), (3,30,0), (4,30,0), (5,30,9), (6,30,0.7), (7,30,0)]
row4...
row5...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文