Matrix from a set of arrays of different length

Viewed 32

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...
0 Answers
Related