Hi,

Not exactly an answer to the question, but rather a cute way to pad an array of 
any rank using a cool feature of ;. cut that I ran into today.
From the dictionary:

u;.0 y applies u to y after reversing y along each axis; it is equivalent to (0 
_1 */$y) u;.0 y .

Using this:

   padop=: &((+$) {. ]) (;.0) (^:2)
   2 padop i.2 3
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 2 0 0
0 0 3 4 5 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
   1 padop i.2 2 2
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

0 0 0 0
0 0 1 0
0 2 3 0
0 0 0 0

0 0 0 0
0 4 5 0
0 6 7 0
0 0 0 0

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

Unfortunately padop must be an adverb in order to be tacit (unless there is 
maybe some wicked way). The corresponding explicit verb could be used for a 
default left argument.

Anyway just an illustration of one of cut’s many powers that I probably often 
overlook.

Cheers,
Louis

> On 5 May 2019, at 09:44, 'robert therriault' via Programming 
> <[email protected]> wrote:
> 
> Hi Linda,
> 
> I think that the trick is that the left operand for ^: needs to be a verb. 
> this seems to work.
> 
>    f=:(0 ,.~ 0 ,. 0 ,~ 0 , ])^:[
>   1 f i. 3 4
> 0 0 0  0  0 0
> 0 0 1  2  3 0
> 0 4 5  6  7 0
> 0 8 9 10 11 0
> 0 0 0  0  0 0
>   g=: 4 : '(0 ,.~ 0 ,. 0 ,~ 0 , ])^:x y'
>   1 g i. 3 4
> 0 0 0  0  0 0
> 0 0 1  2  3 0
> 0 4 5  6  7 0
> 0 8 9 10 11 0
> 0 0 0  0  0 0
> 
> Cheers, bob
> 
>> On May 5, 2019, at 12:36 AM, Linda Alvord <[email protected]> wrote:
>> 
>> f=:(0 ,.~ 0 ,. 0 ,~ 0 , ])^:[
> 
> ----------------------------------------------------------------------
> 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