Message Boards Message Boards

GROUPS:

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

Posted 7 months ago
734 Views
|
3 Replies
|
2 Total Likes
|

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.

3 Replies
Posted 7 months ago

One way to do that

f[v_]:= Map[If[# <= threshold, 1, 0]&, v];
outtable2 = Map[f, outtable]
Posted 7 months ago
UnitStep[threshold - outtable]
Posted 7 months ago

Thank you both. This is working great now.

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