I have a Vector x=[1.00, 1.50, 1.00, 2.30, 4.20, 1.00]
and also another one n=[2, 1, 3]
.
I would like to transform my Vector x
into a Vector of Vectors as follows:
x[1] = [1.00, 1.50]
x[2] = 1.00
x[3] = [2.30, 4.20, 1.00]
where in each Vector of x
, the dimension is determined by n
.
What could be the faster way to implement this? Thanks!
Iterators
package (install withPkg.add("Iterators")
:map(t->x[(t[1]+1):t[2]],partition(cumsum([0;n]),2,1))
- Dan Getz