Hi, good question. Here's a sample code that can do this for you where I chose the case of four sites generated like auto sites = SpinHalf(4);. In the code below, psi is an MPS which could be from a DMRG calculation, say:
auto T = ITensor(1.0);
for(auto j : range1(N))
{
T *= psi(j);
}
auto P = permute(T,sites(1),sites(2),sites(3),sites(4));
Print(P);
for(auto n1 : range1(sites(1)))
for(auto n2 : range1(sites(2)))
for(auto n3 : range1(sites(3)))
for(auto n4 : range1(sites(4)))
{
printfln("%d %d %d %d %.12f",n1,n2,n3,n4,P.elt(n1,n2,n3,n4));
}
Does the above code do what you are looking for?