Are you thinking of the monadic case of amend?

   ]x0=:i.5
0 1 2 3 4
   ]x1=:10*x0
0 10 20 30 40
   ]b=:?.5#2
0 1 1 0 0
   b}x0,:x1
0 10 20 3 4


Leigh J. Halliwell wrote:

Björn, that’s a nice solution to my first question; however, I want to know
if there’s a primitive operator for it, something like X SYMBOL Y. And can
anyone help with my second question?  Thanks.
Leigh -----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Björn Helgason
Sent: Tuesday, October 24, 2006 11:39 AM
To: Programming forum
Subject: Re: [Jprogramming] Choose Operators
Is
(0 0;2 1;1 2;0 3){Y
What you are looking for? 2006/10/24, Leigh J. Halliwell <[EMAIL PROTECTED]>:

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.

Sincerely,

Leigh
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



------------------------------------------------------------------------

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

--
Clifford A. Reiter
Mathematics Department, Lafayette College
Easton, PA 18042 USA,   610-330-5277
http://www.lafayette.edu/~reiterc

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to