Reputation: 1586
I have a d
xm
xn
matrix A
(interpretation: for each n
, there are m
vectors of dimension d
). I would like to extend each d-dimensional vector as follows:
Consider a vector v
of dimension d: (1,2,...,d) (it's (x_1,x_2,...,x_d) but I removed the 'x_' for simplicity). The goal is to extend v
to obtain a d*d
vector of the form:
(1,1,...,1,2,...,2,...,d,d,...,d)
Could anybody please suggest me a fast way to do that? (I guess that using a loop and extending each vector at each iteration is very slow.)
Thank you in advance for your help.
Upvotes: 3
Views: 168
Reputation: 221514
Damn!
reshape(permute(repmat(permute(A,[1 4 2 3]),[1 d]),[ 2 1 3 4]),d*d,m,n)
Upvotes: 3