Your question is quite subjective Harvey, so without trying to evoke a deep
argument either way, here is an overview:

There are two general approaches to the type of question you just posted:
(1) Transpose, apply function(s), transpose-back
(2) Apply function to columns (if possible) ... for example using Raul¹s
approach of v /: 2{³1 v

There can be a Œtrade off¹ as to which of the above approaches to write
(both can be best for specific problems), and 'elegance' versus
'performance' is often the criteria applied (what is the point of an elegant
solution if it is too slow on a large array).

The general approach is to try to avoid unnecessary operations (eg creating
copies of data, such as the transpose will do) as this consumes both time
and space (twice here for the transpose and transpose-back), or exactly as
you say "use fewer array operations" (although that is not always the most
efficient solution either).

But sometimes the transpose approach may be better (eg when a number of
row-wise operations combined in composition may prove faster).

The only yardstick one can use is performance using:
   ts=:6!:2 , 7!:2    NB. 'time' , 'space' to execute a phrase

Then test for yourself ...
   ts 'phrase1'
   ts 'phrase2'

and the choice can become your own exercise to verify and substantiate (and
you learn a lot about what is fast/efficient in J).  You can then use the
forum to further verify that you have not missed an 'even better solution'.

Hope this helps, Rob Hodgkinson

On 10/06/08 3:51 PM, "PackRat" <[EMAIL PROTECTED]> wrote:

> Both responses to my recent sorting question worked directly on the
> column in question rather than transposing and working with the
> equivalent row.  Since verbs usually work with rows/lists of data, as a
> beginner I've tended to try to get arrays into a form where I can work
> with one or more rows and then transpose back again.  However, a lot of
> example code I see in the forum, etc., often does NOT transpose arrays
> to a row-oriented format for column work.
> 
>> From a stylistic perspective (since both approaches work), is the
> preference more a matter of using fewer actions (for example, avoiding
> the necessary double array transposition when using rows) or is there
> just a preference in J for dealing with array columns directly?  I'm
> trying to learn from what I see you all write.  Thanks!
> 
> Harvey
> 
> ----------------------------------------------------------------------
> 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