Pascal wrote: "is there a tacit version of unbv?"
Sure,
of=. train o ([ ; an y)f.
S (+/ %#)`'' _.
┌──┐
│+/ % #│
└──┘
(S (+/ %#)`'' _.) (of + ]) 2 3 4
5 6 7
A boxed list of verbs,
S (+/ %#)`'' *:`'' _.
┌──┬──┐
│+/ % #│*:│
└──┴──┘
is easy to handle,
(S (+/ %#)`'
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
Jon, there should have been a final > to unbox the result array
> On 29 Mar 2017, at 8:45 pm, Rob Hodgkinson 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
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,
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 foll
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.
I
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
Look at u;.3 and u;._3
Henry Rich
On 3/29/2017 3:54 AM, 'Jon Hough' via Programming wrote:
T =: 12 12 $ 0 _2 12 100 2 4.5 1 7 _5.5 3.2 120 2 _100 3 5 18 4
--
For information about J forums see http://www.jsoftware.com/forums.
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
Als
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 _
10 matches
Mail list logo