[Jprogramming] {. y produces an array.

Dan Bron j at bron.us
Fri Oct 21 01:47:05 HKT 2011


Raul wrote:
>   {.^:(#@$)  i.-5 4 3 2
> 119
>   {.,  i.-5 4 3 2
> 119

Henry said:
>  Point of nomenclature: every noun has a shape.  
>  All shapes are lists. 
>  The shape of an atom is an empty list.

So Henry's given us a big hint here:
 
	   '' ($,) i.-5 4 3 2
	119

And, if you remember the recent thread "Operations on boolean lists" [1],
the hook ($,) is supported by special code.  Thus:

	   first =: {.@:,`( {.^:(#@$) )`( {.^:_ )`( ''&($,) )
	   DATA =: i.-15#2
NB.  Reasonably large data
   
	   assert (-: 1&|.) first`:0 DATA
NB.  All give identical results
   
	   lrep   =:  (`:6) 1 : '5!:6 {.;:''u'' '
NB.  Convert atomic rep to literal
	   ts     =:  time , space@:]  
	   gts    =:  4 : 'lr; ts (''('','')'',~ lr =. x lrep), ''y'''"0 _
NB.  Gerund time & space
	   cgts   =: (; (%"1 <./))&:>/@:|:@:gts
NB.  Compare ts of gerund;
   
	   first cgts DATA
	+---------+-------------+
	|{.@:,    |   38 228.222|
	|{.^:(#@$)| 20.5 171.722|
	|{.^:_    |72.75 456.278|
	|''&($ ,) |    1       1|
	+---------+-------------+

Not bad.

-Dan
   
[1] Top of operations on boolean lists thread:
http://www.jsoftware.com/pipermail/programming/2011-October/024417.html


-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] On Behalf Of Raul Miller
Sent: Thursday, October 20, 2011 11:15 AM
To: Programming forum
Subject: Re: [Jprogramming] {. y produces an array.

   {.^:(#@$)  i.-5 4 3 2
119
   {.,  i.-5 4 3 2
119

-- 
Raul

On Thu, Oct 20, 2011 at 10:44 AM, Marshall Lochbaum
<mwlochbaum at gmail.com> wrote:
> A more general solution is {.^:(#@$)  , which will strip all the
dimensions
> off the array.
>
> Marshall
>
> On Thu, Oct 20, 2011 at 7:34 AM, Raul Miller <rauldmiller at gmail.com>
wrote:
>
>> {. gets the first item from an array.
>>
>> You might be wanting lim=. {.,y (which will always have lim be a rank 0
>> array).
>>
>> But I do not have a good enough of a mental model of your data
>> structures to say for sure what you want.
>>
>> --
>> Raul
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



More information about the Programming mailing list