[Jprogramming] Unboxing after subarray function
Rob Hodgkinson
rhodgkin at me.com
Wed Mar 29 09:49:53 UTC 2017
Jon, there should have been a final > to unbox the result array
> On 29 Mar 2017, at 8:45 pm, Rob Hodgkinson <rhodgkin at me.com> wrote:
>
> Did you notice my last line ? It specifically gave you an alternative way to unbox the cells you had in IsMax preserving row/column indexes.
>
> Unfortunately it became “line broken” in email, but you can stitch and try … sending again (with spaces if that avoids the line breaking)…
>
> Treat the following line of chars (even if multiple lines) as one line (you may also have to change the “ to the J form (just retype this character after you copy/paste the line) … this works likewise for the 3x3 cells…/Rob
>> ,”1 &. > / , &. > / IsMax
>
>
>
>
>> On 29 Mar 2017, at 8:38 pm, 'Jon Hough' via Programming <programming at jsoftware.com> wrote:
>>
>> Yes, the "stride" of each window is equal to its length, so in this case using ;.3 (with appropriate arguments) gives the same result as ;.1 .
>> Regardless, my problem occurs after this part, I think. The problem is trying to unbox the boxed array, keeping the correct shape and element positions.
>> If there is a way to do this without using ;. that would also be great.
>>
>> Just to reiterate, given an NxN array, T say, create a second NxN array, S say, such that the elements of S are either 1 or 0, depending on whether they are equal to the appropriate MxM subarray's max element, where M divides N. Sorry, that is a pretty ugly definition of the problem.
>>
>> Here's another example (using ;.3):
>>
>> ]T =: 6 6 $ 1 4 100 0 4 3 8 5 200
>> 1 4 100 0 4 3
>> 8 5 200 1 4 100
>> 0 4 3 8 5 200
>> 1 4 100 0 4 3
>> 8 5 200 1 4 100
>> 0 4 3 8 5 200
>>
>> c =: ;.3
>> (2 2 $ 3 3 3 3) ((>./ = ])&.>@:<)c T NB. window has size 3x3 and stride 3x3, so creates 4 3x3 boxes
>>
>>
>> ┌─────┬─────┐
>> │0 0 0│0 0 0│
>> │0 1 0│0 0 0│
>> │0 0 0│0 0 1│
>> ├─────┼─────┤
>> │0 0 0│0 0 0│
>> │0 1 0│0 0 0│
>> │0 0 0│0 0 1│
>> └─────┴─────┘
>>
>> So, the problem is to get rid of the boxes, but keep the shape and positions of the array and its elements.
>>
>> --------------------------------------------
>> On Wed, 3/29/17, Rob Hodgkinson <rhodgkin at me.com> wrote:
>>
>> Subject: Re: [Jprogramming] Unboxing after subarray function
>> To: programming at jsoftware.com
>> Date: Wednesday, March 29, 2017, 6:19 PM
>>
>> Jon, I note Henry’s
>> point about using <;.3 T if you wish to use the 2x2
>> tessellation windows as per Henry’s suggestion, that is
>> fine. (it was my first approach on reading your question
>> too).
>>
>> But I notice you are
>> choosing to “slice” separate subarrays (non overlapping)
>> so I gather your question is a neater way to reconstruct
>> IsMax as a simple 10 10 array ? If so, you gave this:
>> 10 10 $ , > |:"2 <"1
>>> IsMax
>>
>> Then my
>> suggestion is this (which reproduces your final line
>> only):
>>> ,"1&.>/
>> ,&.>/ IsMax
>>
>> HTH,
>> Regards Rob
>>
>>
>>> On 29 Mar 2017, at 6:54 pm, 'Jon
>> Hough' via Programming <programming at jsoftware.com>
>> wrote:
>>>
>>> I should
>> also mention that my verb(s) work for subarrays other than
>> 2x2.
>>> e.g. if T is a 12x12 array
>>> T =: 12 12 $ 0 _2 12 100 2 4.5 1 7 _5.5
>> 3.2 120 2 _100 3 5 18 4
>>> is =: 12 $ 1
>> 0 0
>>> IsMax =:
>> (is;is) ($$((>./=])@:,))&.>@:<
>> interval T NB. max of 3x3 subarrays
>>>
>> 12 12 $ , > |:"2 <"1 > IsMax
>>>
>>> Also creates the
>> correct array.
>>>
>>>
>> --------------------------------------------
>>> On Wed, 3/29/17, 'Jon Hough' via
>> Programming <programming at jsoftware.com>
>> wrote:
>>>
>>> Subject:
>> [Jprogramming] Unboxing after subarray function
>>> To: "Programming Forum" <programming at jsoftware.com>
>>> Date: Wednesday, March 29, 2017, 4:38
>> PM
>>>
>>> I have a NxN
>> matrix.
>>> For each 2x2 subarray of this
>> (keep it simple, N is even), I
>>> want to
>> calculate the maximum value and if the value of that
>>> cell equals the maximum of the 2x2
>> subarray write 1, else
>>> write 0.
>>>
>>> e.g.
>>> NB. T arbitrary 10x10 matrix
>>> T =: 10 10 $ 0 _2 12 100 2 4.5 1 7 _5.5
>> 3.2 120 2 _100 3 5
>>> 18 4
>>>
>>> interval =: ;.1
>>> is =: 10 $ 1 0
>>>
>>> IsMax =:
>>>
>> (is;is) ($$((>./=])@:,))&.>@:<
>>> interval T
>>>
>>> So IsMax shows which elements are the max
>> values of the 4x4
>>> subarrays.
>>>
>>> Now I want to unbox
>> and keep the indices correct.
>>>
>>> This appears to work
>>>
>>
>>> 10 10 $ , > |:"2 <"1
>>> IsMax
>>>
>>> But is
>> incredibly messy. I'm hoping there is a nicer/ more
>>> terse / elegant way to do this.
>>>
>>> Thanks,
>>> Jon
>>>
>> ----------------------------------------------------------------------
>>> 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
>> ----------------------------------------------------------------------
>> 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