Re: setting elements of an array based on a condition

• To: mathgroup at smc.vnet.net
• Subject: [mg87189] Re: setting elements of an array based on a condition
• From: Oliver Ruebenkoenig <ruebenko at uni-freiburg.de>
• Date: Thu, 3 Apr 2008 05:17:52 -0500 (EST)
• References: <fsvejr\$ssp\$1@smc.vnet.net>

```Hello Claus,

On Wed, 2 Apr 2008, Claus wrote:

> Hello,
> I have one array, W, which for testing purposes has 25 rows and 50 columns.
> There are two more things I want to accomplish with this:
> 1) I want to set all elements of W which are smaller than zero to zero.
> 2) Then I want to calculate the sum of the elements in each column of W.
> How can I do this?
>
> The code below shows how I get to W.
>
> Thank you for your help!
> Claus
>
>
>
> X = RandomReal[{0, 1}, 50];
> Y = RandomReal[{0, 1}, 50];
>
> BinWidth = 0.2;
>
> xyzVals2 = Table[
>    {i/(1/BinWidth) + (BinWidth/2)
>     , j/(1/BinWidth) + (BinWidth/2)
>     }
>    , {i, 0, (1/BinWidth) - 1}
>    , {j, 0, (1/BinWidth) - 1}];
>
> RasterPtsVals = Partition[Flatten[xyzVals2], 2]
>
> RasterX = RasterPtsVals[[All, 1]]
> RasterY = RasterPtsVals[[All, 2]]
>
> XDiffSq = (RasterX - a /. a -> X)^2;
> YDiffSq = (RasterY - b /. b -> Y)^2;
> Dist = Sqrt[(XDiffSq + YDiffSq)];
>
> W = 1 - (Dist/Radius)
>
>

tmp = (W + Abs[W])/2;
Plus @@@ Transpose[tmp]

hth,

Oliver Ruebenkoenig, <ruebenko AT uni-freiburg.de>

```

• Prev by Date: What's DSolve's output when it cant find a solution ?
• Next by Date: Re: Mixed Numerical Derivatives
• Previous by thread: Re: setting elements of an array based on a condition
• Next by thread: Re: setting elements of an array based on a condition