# Deleting sublists based on a criterion

I generated a list as follows

m=7;
pinv=5;
p=1/pinv;
permutations=Permutations[Join[ConstantArray[1,m-1],ConstantArray[0,pinv]]]
numberofhypothesis=Binomial[pinv+m-1,m-1];

hypothesisset[index_]:={p*Max[Part[Position[Part[permutations,index],1],1]-1],p*Max[Part[Position[Part[permutations,index],1],2]-Part[Position[Part[permutations,index],1],1]-1],p*Max[Part[Position[Part[permutations,index],1],3]-Part[Position[Part[permutations,index],1],3]-1],p*Max[Part[Position[Part[permutations,index],1],4]-Part[Position[Part[permutations,index],1],3]-1]};
hypothesissets=Array[hypothesisset,numberofhypothesis]


Next, I wanted to remove those sublists that had entries greater than 1. I tried looking up DeleteCases and Select, but it was hard to write out the condition. Is there a way to remove them?

• Oops, yes, let me see if I can edit it Commented Mar 10, 2022 at 2:24
• DeleteCases[data, _List?(Max[#] > 1 &), {-2}] or adjust the level spec as needed. Commented Mar 10, 2022 at 2:46
• Could you please consider changing the title? It is in contradiction with what you describe in the OP. Perhaps "Deleting a sublist based on a criterion" is more appropriate. And I almost forgot...
– user49048
Commented Mar 10, 2022 at 3:01
• Welcome to Mathematica SE. To get started:1) take the introductory tour now,2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge,3) remember to accept the answer, if any, that solves your problem, by clicking checkmark sign,4) give help too, by answering questions in your areas of expertise.
– user49048
Commented Mar 10, 2022 at 3:01
• Thank you, and edited! Commented Mar 15, 2022 at 9:08

If I run

Position[Flatten[hypothesissets], _?(# > 1 &)]

{}

which means that there is not a single element for which it holds

element > 1

within said list.

I am assuming that I understood the question properly, so with the following toy matrix that contains elements bigger than 1

test = {{1, 1/2, 1/3, 1/4}, {1, 2, 3, 4}, {0, 1, 2, 1/2}, {1/3, 1/6,
1/9, 1/11}};


this works

Select[test, Max[##] <= 1 &]


{{1, 1/2, 1/3, 1/4}, {1/3, 1/6, 1/9, 1/11}}

If the author of the OP meant to delete a sublist if an element appears more than once, the following does the trick.

Assume the toy model

test = {{1, 1/2, 1/3, 1/4}, {1, 2, 3, 4}, {0, 2, 2, 1/2}, {1/3, 1/3,
1/3, 1/11}};


and then

Select[test, Signature[#] != 0 &]


gives

{{1, 1/2, 1/3, 1/4}, {1, 2, 3, 4}}

• Select[test, Max[#] <= 1 &] also works. Commented Mar 10, 2022 at 4:46
• @AsukaMinato thanks for pointing this out! Really nice!
– user49048
Commented Mar 10, 2022 at 4:51
• Thank you for all your help! With the solutions, I managed to solve my Bayesian Learning problem Commented Mar 15, 2022 at 9:07