(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,
e83diagonals =: |:L:_1([:,.>)L:_1 ;/ (|:</."2(|:(($mat) $ i.#mat)),:(($mat)
$ i.#mat)),<0
and I put each diagonal of coordinates into a box, and then I found that I
could search it and determine which box my coordinates were in.
diag =. {.I.(= <./) (>e83diagonals) i."(2,1) (y0row,y1col)
mat =: i. 6 6 NB. as an example
I then decided that I wanted to gather those coordinates into a 2 by n
list, so that I could process the items in the list by diagonal.
I could not figure out how to gather those items into a 2 by n list.
I finally allocated a global array and wrote a function that did the
gathering as a side effect, in the interest of expediency.
I looked through phrases and such, and could not figure out how to pull the
items. I have run into this before, so if you want to help, the issue of
how to get the coordinates into a 2 by x array, but the next time I need to
crack a set of boxed arrays into a matrix or list I won't know how to do
it, so please answer from that viewpoint, maybe I'll know how next time.
(OK, there are a lot of operators in J. It turns out that monadic ; known
as raze, does exactly this. It does exactly this. I looked at vocabulary
and phrases for a half hour before writing the side effect function, sigh,)
z83 =: ; }.}. |.e83diagonals
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?
--
Of course I can ride in the carpool lane, officer. Jesus is my constant
companion.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm