Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: Masked array operations

  • To: mathgroup at
  • Subject: [mg1666] Re: [mg1613] Masked array operations
  • From: Lou Talman <me at>
  • Date: Tue, 11 Jul 1995 04:27:14 -0400


  Chi[0, x_] := {};
  Chi[1, x_] := {x};
  mask = {1, 0, 0, 1, 0, 1};
  data = {1, 2, 3, 4, 5, 6};

  Inner[Chi, mask, data, Join]

  {1, 4, 6}

Begin forwarded message:

>Date: Thu, 6 Jul 1995 22:12:55 -0400
>From: msreeve at (Mark D. Reeve)
>Subject: [mg1613] Masked array operations 

Suppose I have a data array, say 1-D, and a boolean (1/0 or True/False)  
of the same length.  How I can I reduce the data array by the boolean  

e.g. data={1,2,3,4,5,6};

I want something like the APL operator "/" such that mask/data yields 

{1,4,6}.  Ideally this operator should work over any arbitrary dimension 

of the array.

You can do it with Select by first pairing the data and the mask, but 

this seems slow.  The best I have come up with is:


where dim is the dimension (first is 1) over which to perform the 

reduction.  This seems rather unwieldy for such an outwardly simple 

operation.  Can anyone improve it?

Mark Reeve
msreeve at  OR  mreeve at

  • Prev by Date: Re: rhs of SetDelayed
  • Next by Date: Re: rhs of SetDelayed
  • Previous by thread: Masked array operations
  • Next by thread: Re: Masked array operations