Re: What is the fastest way to threshold data?

• To: mathgroup at smc.vnet.net
• Subject: [mg85924] Re: [mg85898] What is the fastest way to threshold data?
• From: Carl Woll <carlw at wolfram.com>
• Date: Thu, 28 Feb 2008 02:42:19 -0500 (EST)
• References: <200802270924.EAA16019@smc.vnet.net>

```Kevin J. McCann wrote:

>I have some 3d data {{x1,y1,z1},{x2,y2,z2},...} and I would like to set
>the z-values to zero if they fall below zero. More generally, I would
>like to set z to a threshold value if it is at or below a threshold.
>This seems as though it should be an easy enough thing to do, but the
>only way I have figured out is to parse out the z-vector, do
>
>
>then
>
>and rebuild the {x,y,z} data.
>
>Kevin
>
>
I would do this as follows:

In[101]:= mat = RandomReal[{-1, 1}, {10, 3}]

Out[101]= {{-0.574316, 0.0429482, 0.679336}, {0.696716, 0.0813526,
-0.886499}, {0.622524, 0.687576,
0.197264}, {-0.196498, -0.263147, -0.538339}, {0.454982, 0.0226721,
-0.609805}, {-0.116741, -0.491716, -0.561586}, {0.760373, -0.482596,
0.46804}, {-0.125821, 0.899048, 0.606259}, {0.760627, -0.441741,
-0.668888}, {-0.767075, 0.646638, 0.737813}}

In[102]:= mat[[All, 3]] = Clip[mat[[All, 3]], {0, Infinity}];

In[103]:= mat

Out[103]= {{-0.574316, 0.0429482, 0.679336}, {0.696716, 0.0813526, 0.},
{0.622524, 0.687576, 0.197264}, {-0.196498, -0.263147,
0.}, {0.454982, 0.0226721, 0.}, {-0.116741, -0.491716, 0.}, {0.760373,
-0.482596, 0.46804}, {-0.125821, 0.899048,
0.606259}, {0.760627, -0.441741, 0.}, {-0.767075, 0.646638, 0.737813}}

Carl Woll
Wolfram Research

```

• Prev by Date: Re: "Assuming"
• Next by Date: Re: Version 6.0.2
• Previous by thread: Re: What is the fastest way to threshold data?
• Next by thread: Re: What is the fastest way to threshold data?