Your solution is very good.

Using some examples.

   2 4 $ 1;2;a:
+-+-+-+-+
|1|2| |1|
+-+-+-+-+
|2| |1|2|
+-+-+-+-+

  >   2 4 $ 1;2;a:
1
2
0
1

2
0
1
2
  $ >   2 4 $ 1;2;a:
2 4 1


  {.@>   2 4 $ 1;2;a:
1 2 0 1
2 0 1 2
  $ {.@>   2 4 $ 1;2;a:
2 4


Note:
 > is already rank 0
 monadic @ is typically preferred to & (unless duality necessary)


--- "Leigh J. Halliwell" <[EMAIL PROTECTED]> wrote:

> Dear Dan and R.E.Boss:
>  
> Thank you for your solutions.  I now understand a little better the
> all-important "Rank" concept.  I agree, one should make the operation return
> the right rank, rather than afterward reduce the rank.
>  
> My problem came when unboxing a matrix of scalars, in which there were some
> empty boxes for missing values (like empty cells from a spreadsheeet range).
> I now see that a: (ace) has rank 1.  It is not really an empty box, but a
> box containing a zero-element vector (I guess that you can't have a really
> empty box in J).  Hence, if there is an ace in the matrix, the operation >"0
> will have the shape (($Matrix), 1).  And the cells will unbox as zeros (more
> accurately, as 1$0).  I solved the problem with ({. & >)"0.  This one-step
> solution seems more efficient that the two steps >"0 and {."0.
>  
> I also just realized that an atom (scalar) can be produced from (i.0) $
> scalar, which is just as it ought to be according to J rank theory.
> Sometimes primitives seem quirky, but here everything makes sense.
>  
> Sincerely,
>  
> Leigh
>  
> -----Original Message-----
> So, now that I've given you the bandaid, I'd like to teach you preventative
> medicine.  You should (nearly) always be able to predict the ranks of the
> results produced by your code.
>  
> If you cannot, and you find you "need to remove a trailing axis", it's
> better to investigate why that's so, and modify the code that produces the
> trailing axis, rather than removing it ex post facto.
>  
> If you post a small working example of the code that's causing you trouble,
> we'll probably be able to explain what's wrong, and help you fix it.
>  
> -Dan
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to