Re: Binary Vector Manipulation
- To: mathgroup at smc.vnet.net
- Subject: [mg84123] Re: Binary Vector Manipulation
- From: dh <dh at metrohm.ch>
- Date: Mon, 10 Dec 2007 20:45:18 -0500 (EST)
- References: <fjj183$frv$1@smc.vnet.net>
Hi Tara,
if I understand right, you want a "numerical" Or:
numOr[x1_,x2_]:=If[x1==1||x2==1,1,0];SetAttributes[numOr,Listable];
b=numOr[a,b]
Now we will zero a random position in b until we have a ratio of 50/50:
n=Length[b];
While[0.5<(Plus@@b)/n, b[[RandomInteger[{1,n}]]]=0]
hope this helps, Daniel
Tara.Ann.Lorenz at gmail.com wrote:
> I am need of assistance programming the following scenario:
>
> I have two vectors composed of 0's and 1's. Vector "A" has 5% 1's
> (and 95% 0's) while Vector "B" has 50% 1's and 50% 0's.
>
> First, I would like to change Vector B to have a "1" in every place
> that Vector A also has a "1" (in other words, I will then have more
> than 50% 1's in Vector B once this step is completed).
>
> Then, I would like to *randomly* return Vector B back to a 50/50
> distribution of 1's and 0's.
>
> I greatly appreciate any proposed programming methods.
>
> Thank you,
> Tara
>
>
>