I would like to turn a list which looks like this one:
{{-1, -1, -1}, {-1, 2, 3}, {-1, -1, 2}, {2, 3, 4}}
into one which looks like that one:
{{}, {2, 3}, {2}, {2, 3, 4}}
Is there an efficient way to do this?
|
I would like to turn a list which looks like this one:
into one which looks like that one:
Is there an efficient way to do this? |
||||
|
|
|
Replacing -1 with an empty
If there are expressions containing
Comparing this solution with the
Some other alternatives based on the answer by yulinlinyu (and comments):
If the actual |
|||||||||
|
|
Translation of python.
A recursive version:
|
||||
|
|
|
This :
Addressing @Sjoerd's comment, if the list is 2 dimensional one can adjust the level to 2.
|
|||||||
|
|
If your (ragged) array is entirely numeric, and your desired operation is to remove all negative values, you could use this:
This should prove competitively fast as well. |
|||
|
|
|
How about this?
Edit 1:
Or
Edit 2:
|
|||||||||||
|