0
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ Oops, yes, let me see if I can edit it $\endgroup$
    – Jin Siang
    Commented Mar 10, 2022 at 2:24
  • 4
    $\begingroup$ DeleteCases[data, _List?(Max[#] > 1 &), {-2}] or adjust the level spec as needed. $\endgroup$
    – Bob Hanlon
    Commented Mar 10, 2022 at 2:46
  • $\begingroup$ 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... $\endgroup$
    – user49048
    Commented Mar 10, 2022 at 3:01
  • $\begingroup$ 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. $\endgroup$
    – user49048
    Commented Mar 10, 2022 at 3:01
  • 1
    $\begingroup$ Thank you, and edited! $\endgroup$
    – Jin Siang
    Commented Mar 15, 2022 at 9:08

1 Answer 1

1
$\begingroup$

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}}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.