Thanks Raul, your solution is much nicer than mine.

--------------------------------------------
On Wed, 3/29/17, Raul Miller <[email protected]> wrote:

 Subject: Re: [Jprogramming] Unboxing after subarray function
 To: "Programming forum" <[email protected]>
 Date: Wednesday, March 29, 2017, 9:01 PM
 
 Here's a
 generalization which works on your first example (which
 happens to also be a better example):
 
 maxes=: [ # [ #"1 (2 2 $
 [) >./@,;.3 ]
 
    T =: 10 10 $ 0 _2 12 100 2 4.5 1
 7 _5.5 3.2 120 2 _100 3 5 18 4
    2 maxes T
 120 120
 100 100  18  18   7   7  12  12
 120 120 100 100  18 
 18   7   7  12  12
 100 100  18  18   7   7
 120 120 4.5 4.5
 100 100  18 
 18   7   7 120 120 4.5 4.5
   7   7  12  12 120 120 4.5 4.5 
 18  18
   7   7  12  12 120
 120 4.5 4.5  18  18
 120 120 4.5
 4.5   7   7  18  18 120 120
 120 120 4.5 4.5   7   7 
 18  18 120 120
 4.5 4.5  18  18 120 120 
 12  12 100 100
 4.5 4.5  18  18 120 120 
 12  12 100 100
    2 (]=maxes)
 T
 0 0 0 1 0 0 0 1 0 0
 1 0 0
 0 0 1 0 0 0 1
 1 0 0 0 1 0 0 1 0 0
 0 0 1 0 0 0 0 0 0 1
 0 1 0 0 1 0
 0 0 0 1
 0 0 0 1 0 0 1 0 0 0
 0 1 0 0 0 0 1 0 0 0
 0 0 0 1 0 1
 0 0 1 0
 0 0 0 1 0 0 0 1 1 0
 1 0 0 0 0 1 0 0 0 0
 
 Thanks,
 
 -- 
 Raul
 
 
 On
 Wed, Mar 29, 2017 at 5:46 AM, Raul Miller <[email protected]>
 wrote:
 >    maxes=: 3#3#"1 (2 2$3)
 >./@,;.3 ]
 >    maxes T
 > 200 200 200 200 200 200
 > 200 200 200 200 200 200
 > 200 200 200 200 200 200
 > 200 200 200 200 200 200
 > 200 200 200 200 200 200
 > 200 200 200 200 200 200
 >    (= maxes) T
 > 0 0
 0 0 0 0
 > 0 0 1 0 0 0
 > 0 0 0 0 0 1
 > 0 0 0 0 0
 0
 > 0 0 1 0 0 0
 > 0 0
 0 0 0 1
 >
 > Like
 that?
 >
 > Thanks,
 >
 > --
 > Raul
 >
 >
 > On Wed, Mar 29, 2017
 at 5:38 AM, 'Jon Hough' via Programming
 > <[email protected]>
 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 <[email protected]>
 wrote:
 >>
 >> 
 Subject: Re: [Jprogramming] Unboxing after subarray
 function
 >>  To: [email protected]
 >>  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 <[email protected]>
 >>  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 <[email protected]>
 >>  wrote:
 >> 
 >
 >>  > Subject:
 >>  [Jprogramming] Unboxing after
 subarray function
 >>  > To:
 "Programming Forum" <[email protected]>
 >>  > 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to