Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Binary Vector Manipulation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84117] Re: [mg84087] Binary Vector Manipulation
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Mon, 10 Dec 2007 20:42:07 -0500 (EST)
  • References: <21283123.1197312138331.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

n = 1000;
a = RandomChoice[{95, 5}/100 -> {0, 1}, n];
b = RandomChoice[{1, 1}/2 -> {0, 1}, n];
Total /@ {a, b}

{55, 521}

b = BitOr[a, b];
Total@b

546

b = RandomChoice[{1, 1}/2 -> {0, 1}, n];
Total@b

467

Bobby

On Mon, 10 Dec 2007 03:32:36 -0600, <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
>
>
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Binary Vector Manipulation
  • Next by Date: Re: Inset problems & Export
  • Previous by thread: Re: Binary Vector Manipulation
  • Next by thread: Re: Binary Vector Manipulation