a = Table[i, {i, 1, 10}]
Drop[a, {5, 8}]
If go with the above procedure, It will delete all the elements from between position 5 to 8. How to drop elements which are a position 5 and position 8 using drop function.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityUse instead Delete
, in this way:
a = Table[i, {i, 1, 10}];
Delete[a, {{5}, {8}}]
(*
{1, 2, 3, 4, 6, 7, 9, 10}
*)
By the way, you can be far more efficient:
a = Range[10]
Delete[a, Partition[{3, 5, 8, 9}, 1]]
comes to mind... if the list of positions gets longer.
$\endgroup$
Nov 29, 2018 at 8:04
Drop[a, {5, 8, 3}]
{1, 2, 3, 4, 6, 7, 9, 10}
Fold[Drop[#, {#2}] &, a, Reverse[{5, 8}]]
{1, 2, 3, 4, 6, 7, 9, 10}