[Jprogramming] Shifting an Array
Henry Rich
henryhrich at gmail.com
Mon Jan 9 14:58:30 UTC 2017
Better on big arrays:
(2 _2 {."0/ _1 1) |.!.'x'"1 _ a
This produces shape 2 2 3 4 which you could convert to shape 4 3 4 using
(,/)
Henry Rich
On 1/9/2017 9:07 AM, Skip Cave wrote:
> Thanks, Henry! Yes, I meant a shape of 4 3 4.
>
> Skip Cave
> Cave Consulting LLC
>
> On Sun, Jan 8, 2017 at 12:28 PM, Henry Rich <henryhrich at gmail.com> wrote:
>
>> _1 1 (|.!.'x'"1"0 _ , |.!.'x'"0 _) a
>>
>> result has shape 4 3 4.
>>
>> Henry Rich
>>
>>
>> On 1/8/2017 12:59 PM, Skip Cave wrote:
>>
>>> I have a 3x4 array a:
>>>
>>> a
>>>
>>> abcd
>>>
>>> efgh
>>>
>>> ijkl
>>>
>>>
>>> I want a verb to create an array b that shifts a in 4 directions, and
>>> fills
>>> with 'x', creating a 2x3x4 array
>>>
>>>
>>> f a
>>>
>>> xabc
>>>
>>> xefg
>>>
>>> xijk
>>>
>>>
>>> bcdx
>>>
>>> fghx
>>>
>>> jklx
>>>
>>>
>>> xxxx
>>>
>>> abcd
>>>
>>> efgh
>>>
>>>
>>> efgh
>>>
>>> ijkl
>>>
>>> xxxx
>>>
>>> What is the most efficient J way to do this? The order of the 4 shifts are
>>> not important.
>>>
>>> Skip
>>> ----------------------------------------------------------------------
>>> 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