# Deleting list elements at a certain level

I have a large list of 3 by 3 matrices such that the dimensions of the list for an example 100 matrices would be: {100,3,3}

I have written a function that locates all the matrices I do not want and returns their locations in a list, so if 4 matrices are found that fulfill this criteria an example returned list could be: {3,27,56,97}

What I want is to be able to delete the corresponding matrices at these locations so that my list of matrices will now have the dimensions: {96,3,3}

I am sure this is very simple, and I have tried using Drop[] and Delete[], but I cannot get them to operate at the correct level. Thanks in advance for any help!

When you already have a dontWantMat function that returns True or False to say you don't want or want a matrix, then you can use Select

Select[listOfMat, Not[dontWantMat[#]]& ]


If you want to use your list of positions with Delete, you have to be careful because Delete expects the form Delete[mats, {{p1},{p2},{p3},..}] where p1,... are the position. Here is a short example which helps you

locations = {4, 6};
Delete[{1, 2, 3, 4, 5, 6}, List /@ locations]

(* {1, 2, 3, 5} *)

• Thank you, I will try and rewrite my function so that it gives a true or false answer, but that might be tricky for someone of my lack of Mathematica skills! Currently my function just gives me a list of the locations of my unwanted matrices.
– Jack
Dec 3, 2014 at 17:48
• @Jack But you do calculate the locations. That's why I thought it is easier to directly extract it using Select. Let me edit my answer to give you a solution with Delete Dec 3, 2014 at 17:53
• Excellent! Thank you. I am sure the way I am going about things is not the most elegant, but I am learning, when I have the chance I will go back and rewrite.
– Jack
Dec 3, 2014 at 17:59