Phrases/Arrays

From J Wiki
Jump to: navigation, search

Array transformations

decirow=:(($ {.&1)~ #) # ]
decicol=:(($ {.&1)~ {:@$) #"1 ]

Decimate the array. Leave only x-th row (column) in array y.

Splitting [0,1] interval

NB.*spl01eq v equal split, all subintervals are equal
NB. y = number of intervals
spl01eq=:%~ i.@>:

Generates sequence r that increases from 0 to 1 in equal steps.

NB.*spl01ap v subinterval lengths form arithmetic progression
NB. x = length of first interval
spl01ap=:[: +/\ 0 , [ + i.@] * -.@* % 2 ! ]

Generates sequence r that increases from 0 to 1 in steps that form arithmetic progression.

NB.*spl01gpr v subinterval lengths form geometric progression
NB. x = ratio of interval lengths
spl01gpr=:[: +/\ 0 , (^ i.) % ^ %&-. [

Generates sequence r that increases from 0 to 1 in steps that form geometric progression with ratio x.

NB.*spl01ol v split into equal overlapping segments
NB. y=k,f where k=number of interval, f fraction of an interval shared
NB. with a neighbour
spl01ol=:3 : 0
   'k f'=.2{.y
   r=.%f+k*1-f
   (,. r&+) (r*-.f)*i.k
)

Split [0,1] into overlapping subntervals. Return (y,2) array of the limits of the intervals.