Message Boards Message Boards

0
|
6427 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Use Map with If to apply a test to a nested list?

Posted 5 years ago

I have the nested list:

outtable={{2936.43, 2010.95, 805.145}, {1277.23, 646.763, 40.0572}, {11.9107, 
  28.5548, 52.7854}, {14.1702, 1305.69, 1775.71}, {412.422, 773.669, 
  726.661}}

I would like to apply a test to the list and output a table of identical dimensions but with "1" if the value in the list is less than a threshold value and 0 if it is not. Here is what I have tried:

threshold = 50;
outtable2 = Map[[If[[#] <= threshold, 1, 0]], outtable]

The output should look like this:

outtable2={{0,0,0},{0,0,0},{1,1,0},{1,0,0},{0,0,0}}

Any help with getting this to work would be appreciated.

POSTED BY: Jamie Dixson
3 Replies
Posted 5 years ago

Thank you both. This is working great now.

POSTED BY: Jamie Dixson
Posted 5 years ago
UnitStep[threshold - outtable]
POSTED BY: Okkes Dulgerci
Posted 5 years ago

One way to do that

f[v_]:= Map[If[# <= threshold, 1, 0]&, v];
outtable2 = Map[f, outtable]
POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract