# Get partial tensor

Hi,

I have seen variants of this question on the forum but unable to find a good solution still. Given a tensor, I want to fix some indices and get the sub-tensor. The present elT function demands all indices be fixed.

Replace the index that needs to be fixed by another 1-dimensional index (using delta tensor). This does select a sub-tensor but I couldn't find a way to change the default index value ("1") to some other value for the 1-dimensional index (to extract other possibilities).

Any leads to do this efficiently will be appreciated.

Thanks

Good to meet you in person and discuss, but I'll also post the answer here.

To fix, clamp, or set an index to a particular value, a good solution is to contract the tensor with another tensor produced by the "setElt" function. (See setElt on this page: http://itensor.org/docs.cgi?vers=cppv3&page=classes/itensor). Calling setElt(i=n) makes an ITensor which has the index "i" and has a component 1.0 in the nth entry, and zero otherwise.

Then you can multiply it by your tensor T like: T *= setElt(i=n).

Best regards,
Miles

commented by (190 points)
Hi Miles,

It was indeed great to meet you in person. Thank you for all the valuable inputs. I'll leave a small function here to get a sub-tensor with a subset of indices fixed. The function assumes that the indices and values are ordered (this is the responsibility of the user).

ITensor
GetSubTensor(ITensor T,std::vector<Index> const &indices,std::vector<int> values )
{
ITensor retT;
for(unsigned int l=0;l<indices.size();l++)
{
if(l==0)
retT = T*setElt(indices[l]=values[l]);
else
retT*=setElt(indices[l]=values[l]);
}
return retT;
}

Thanks