来自一组不同长度阵列的矩阵
我有一组花键,每个样条线将信息作为数组存储。 每个样条都有X_COORD
,z_coord
,field
,但是这些数组的长度,从样条到另一个样条的长度可能会有所不同。
我需要在所有这些花条中形成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_coord
和z_coord
已经具有常数模式,我认为我可以创建一个矩阵删除重复并与每个矩阵关联位置,相关x_coord
,z_coord
和field
通过字典。 但是我是堆栈:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论