_1 (4 : '(,y)([#~ (x|~]) = |~) >:{:$y') i.5 5
5 11 17 23

   _1 (4 : '(,y)([#~ (x|~]) = |~) >:{:$y') i.5 6
6 13 20 27

   3 2 finddiag~ i.5 6
|length error: finddiag
|   3 2     finddiag~i.5 6


R.E. Boss


-----Oorspronkelijk bericht-----
Van: [email protected]
[mailto:[email protected]] Namens Viktor Cerovski
Verzonden: donderdag 10 november 2011 10:52
Aan: [email protected]
Onderwerp: Re: [Jprogramming] selecting from two different matrices based on
a comparison.


I find your post quite convoluted.  Here's what I read:

Nick Simicich-2 wrote:
> 
> (I figured out an answer for the first question - I don't ask unless I
> search thoroughly, and I finally found it, so I am going to leave it in
> case the answer helps someone else.)
> 
> I have an array that can be any of a couple different square sizes. I
> wanted to determine which of the diagonals the coordinates I was
> processing
> was, so I made a list of the coordinates that were on the diagonals,[...]
> 
Problem: 
 Given a square matrix, return diagonal that contains element with
coordinates i j.

Solution:

   finddiag =: ,@[ #~ -/@] = ,@:(-/~@i.@#)@[

The solution uses the fact that i-j (i and j are in y) gives  the number of
the diagonal, 
and then uses the number to extract the corresponding diagonal from x (the
matrix.)

   ]mat=.i.5 5
 0  1  2  3  4
 5  6  7  8  9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24

   mat finddiag 3 2
5 11 17 23

   (<3 2){mat
17

Note that finddiag does not make coordinates of diagonal elements.



> I have a second question.  I wanted to make two x by x matrices, and
> compare one of those matrices to a scalar, building a single matrix by
> extracting from each one.  What I wanted to do was to code some variation
> of.  I had a matrix where the filled in pieces were ordinary numbers and
> the placeholders were _.  I had a second matrix that had candidates, but
> they were not
> 
> (a=b) { mat1,.mat2
> 
> That does nothing like I want - because it just plain does not work. 
> Every
> zero and one selects the whole array, and changing the rank of {, as {"1,
> {"2 etc just does not work.
> 
> What I ended up doing was
> 
> ((a=b)*mat1)+(-.a=b)*mat2
> 
> Now, that worked because I happened to have numeric matrices.  If I'd had
> character arrays, I might have had to map them into numeric arrays to get
> this sort of thing to work at all.
> 
> Is the math trick the only way to do this?
> 
Here I couldn't formulate a problem based on your post.
-- 
View this message in context:
http://old.nabble.com/selecting-from-two-different-matrices-based-on-a-compa
rison.-tp32816282s24193p32817267.html
Sent from the J Programming mailing list archive at Nabble.com.

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

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

Reply via email to