The only difference between data for single time point and data for multiple time points is that single time point data is just same multiple time points data but having just 1 entry.
In that sense any function working with multiple points can also work with single point just by providing to them array consisting of 1 entry with this time point data.
Suppose you have some data for single time point, this data is any array a0
of any shape, for example you have 1D array a0
of shape (10,)
i.e. having 10 features.
Then you can convert this array to 2D array of multiple time point datas just by converting it to shape (1, 10)
this is done for numpy array by short syntax a_mult = a0[None]
or another way to do that with same result is a_mult = np.expand_dims(a0, 0)
, just longer syntax.
After your a0
is converted to a_mult
you can use a_mult
in any function later that accepts multiple time points datas. Example code below:
Try it online!
import numpy as np
a0 = np.array([1,2,3,4,5])
print(a0.shape, a0)
a_mult = a0[None]
print(a_mult.shape, a_mult)
# Now call your multi-point function f_predict(a_mult)
outputs
(5,) [1 2 3 4 5]
(1, 5) [[1 2 3 4 5]]
Similar thing can be done for opposite case, i.e. when you have multiple time points datas and you want to give them to a function that accepts just one time point. This is also achieved easily by indexing your array and having loop, e.g. if you have a_mult
array with multiple points then to convert it to single point just do a0 = a_mult[k]
where k
is any integer ranging from 0
through number_of_time_points - 1
. k
can be iterated through regular Python loop. Example code below:
Try it online!
import numpy as np
a_mult = np.array([
[1,2,3,4,5],
[6,7,8,9,10],
])
print(a_mult.shape)
print(a_mult)
f_predict = lambda x: np.sum(x) # Simple function, just does a sum of elements
res = np.zeros((a_mult.shape[0],), dtype = np.int64)
for k in range(a_mult.shape[0]):
a0 = a_mult[k]
# Now call your single-point function f_predict
# and store result into res
res[k] = f_predict(a0)
print(res)
# Same as in code above can be achieved by next short syntax
res = np.array([f_predict(a_mult[k]) for k in range(a_mult.shape[0])])
print(res)
outputs
(2, 5)
[[ 1 2 3 4 5]
[ 6 7 8 9 10]]
[15 40]
[15 40]