Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.9K Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Select certain elements of sublists of a list

Posted 6 years ago

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

POSTED BY: Laurens Wachters
3 Replies

Thanks, Marco. That is it. Cheers, Laurens

POSTED BY: Laurens Wachters

Well, in fact you do not even need the Flatten or Partition:

Select[# < 0 &] /@ list

Cheers,

Marco

POSTED BY: Marco Thiel

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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard