I am trying to do something simple in numpy, and I'm sure there should be an easy way to do this.
Basically, I have a list of n vectors with different lengths. If v1[i] is the ith entry of the first vector, then I want to find an n dimensional array A such that
A[i,j,k...] = v1[i] v2[j] v3[k] ...
My problem is that:
outer takes only two vector arguments.
einsum requires a parameter like "abcd ..." which seems superfluous.
kron requires what seems like a pretty complicated restructuring, and takes only two arguments.
I would like to avoid as many difficulties as possible in order to avoid errors. Therefore, I prefer one team.
So far, I have everything I have:
vs = [v1, v2, v3 ...] shape = map(len, vs) # specify the orientation of each vector newshapes = diag(array(shape)-1)+1 reshaped = [x.reshape(y) for x,y in zip(vs, newshapes)] # direct product A = reduce(lambda a,b: a*b, reshaped, 1)
python arrays numpy
Lucas
source share