x=: 0 2 1 0
y=: i.3 4
x}y
0 9 6 3
x {"_1 |: y
0 9 6 3
x0=: 111 222 444 555 333
x1=: 2 3 5 7 11
b=: 0 1 0 0 1
b {"_1 x0,.x1
111 3 444 555 11
----- Original Message -----
From: "Leigh J. Halliwell" <[EMAIL PROTECTED]>
Date: Tuesday, October 24, 2006 8:07 am
Subject: [Jprogramming] Choose Operators
> Dear J Forum:
>
> I have two questions about selecting, or choosing.
>
> 1) There is a m-element vector X whose elements belong to i. n.
> And there
> is an (mxn) matrix Y. I want the n-element vector Z whose jth
> element is
> (X(j), j). In other words, X tells the rows of the elements to
> choose from
> the columns of Y. As an example:
>
> X =. 0 2 1 0
> Y =. i. 3 4
> Then Z =. 0 9 6 3
>
> I believe that I once saw a J primitive that does this; but I
> can't find it
> now.
>
> 2) X0 and X1 are numeric vectors, and B is a Boolean vector. They
> all have
> the same length. I'd like to select from X0 where B is 0, and
> from X1 where
> B is 1. I try the expression:
>
> X1 [^:B X0
>
> But the adverb ^:B wants to get two-dimensional, i.e., to apply
> each B to
> every pair of X1 and X2. How can I make J to apply the adverb one-
> to-one
> with the arguments? Thanks.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm