Suppose I have the following list: list = {{-1, 4, -5, 6}, {-5, - 4, 3, 1}}
Now I want to select only the negative elements of each sublist of this list.
So I would like to get the following result: {{-1,-5},{-5,-4}}.
I have tried GreaterThan[0] /@ list, but that does not work, although Max /@ list does work if one wants the maximum value of each sublist, and also Total /@ list if one needs the total of each sublist.
How do I solve this problem?
Thanks in advance for your help.
.
Hi Laurens,
The easiest I can think of is the following:
list = {{-1, 4, -5, 6}, {-5, -4, 3, 1}};
l1 = Flatten[list] // Select[# < 0 &];
Partition[l1, 2]
{{-1, -5}, {-5, -4}}
Best Regards
Christos
Well, in fact you do not even need the Flatten or Partition:
Select[# < 0 &] /@ list
Cheers,
Marco
Thanks, Marco. That is it. Cheers, Laurens