How do I build a specific structure of a 2D array of 1D arrays (i. row vectors) to meet the specific
structure of a legacy programme I am maintaining?
I can generate the right content, in this form
all_measurements[:12]
array([[0. , 0. , 0. , 2. ],
[0.02 , 0.334, 0.04 , 2.24 ],
[0.04 , 0.668, 0.08 , 2.48 ], …..
but the existing programme needs it in this form
array([array([[0. , 0. , 0. , 2. ]]),
array([[0.02 , 0.334, 0.04 , 2.24 ]]),
array([[0.04 , 0.668, 0.08 , 2.48 ]]),
Here is the code I am currently using
import numpy as np
dt = 1/50; nt = 350
Vh = 16.7; Vv = 20.6; Vy = 2
gg = -10; v0 = +2it = np.arange(nt)
ts = dt * itall_measurements = []
for i in range(12):
row = np.array([ts[i], Vhts[i], Vyts[i], (v0 + ts[i]*(Vy – gg))])
all_measurements.append(row)all_measurements = np.array(all_measurements)
The code above generates the test case data, but the parser rejects the data in this format with the error message
too many indices for array: array is 1-dimensional, but 2 were indexed
measurements[row_list[np.where(column_list == i)[0]],:])