What is the inverse of the Position
?
I have an array which contains the positions of elements and I want a function which returns an List which contains 1 where those elements are and 0 elsewhere. For example, the List {1, 5}
would return {1,0,0,0,1}
or {2,1,4}
would return {1,1,0,1}
. Additional arguments might need to be supplied for length etc. (Technically, this function is a inverse of restricted version of the Position function)
I realize that I could do with Table
but it seems like this would be a common enough process that there would be a built in function for this. However, I have not been able to find it in the documentation.
Reverse[IntegerDigits[Tr[2^(#-1)],2]]&
s/b quite efficient. Add the length argument toIntegerDigits
if you want a mask matching some arbitrary length. $\endgroup$Position
... the true inverse ofPosition
, i.e. a function that takesPosition
's output and returns its input, isExtract
$\endgroup$