My input is a product of the variable x
with index:
x[1]^2 x[5] x[7]
How do I extract the indices of the above product to get the list {1,1,5,7}
as an output? Note 1 appears twice in the list since x[1]
is squared.
I would like this code to work for any product of x[j]^n
, where both j and n will be given integers.
Cases[expr, x[i_]^p_. :> Table[i, p], {1}] // Flatten
$\endgroup$Subscript
and using indexed variables instead! This is the way to go! :) $\endgroup$