       Re: setting elements of an array based on a condition

• To: mathgroup at smc.vnet.net
• Subject: [mg87160] Re: setting elements of an array based on a condition
• From: dh <dh at metrohm.ch>
• Date: Wed, 2 Apr 2008 05:58:11 -0500 (EST)
• References: <fsvejr\$ssp\$1@smc.vnet.net>

```
Hi Claus,

to set elements <0 to 0 you may use:

W/. x_/;x<0 -> 0

Adding all elements in a column is easier done if you Transpose W first

so that you add all elements in a row. This can be done by:

Total /@ W

hope this helps, Daniel

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)

>

```

• Prev by Date: Re: Mixed Numerical Derivatives
• Next by Date: Re: setting elements of an array based on a condition
• Previous by thread: Re: Mixed Numerical Derivatives
• Next by thread: Re: setting elements of an array based on a condition