On 9/5/12, pascha <[email protected]> wrote:
> I have a huge matrix (say n x m) and I want to drop the columns numbered
> with
> mutiple of 3 (i.e. 3th, 6th, 9th,..)
> how can I achieve that?
Roger already showed you a good way, but let me show some others.
Let me use this matrix as an example input.
]d =: (?.6 13$31){a.{~(5$45),97+i.26
-n-ejbshgulpx
efefbiplq-zv-
-stxea---bjt-
gup-q-nihzt-n
h--zlb-h-klmy
snfjtbeanjjya
First, a variant on Roger's solution: this still uses the (#"1) dyad
to do the actual work.
(2>3|i.#{.d)#"1 d
-nejshulx
effbpl-z-
-sxe--bj-
gu-qniztn
h-zl-hkly
snjteajja
Secondly, let's use the infix adverb, as I like that adverb. This
leads to some short code.
,._3}:\"1 d
-nejshul
effbpl-z
-sxe--bj
gu-qnizt
h-zl-hkl
snjteajj
Third, a fun but complicated way, using the cut conjunction.
,./ {. (0 3,:_ 2) ];.3 d
-nejshulx
effbpl-z-
-sxe--bj-
gu-qniztn
h-zl-hkly
snjteajja
Last, a horrible abomination so ugly that nobody in their right mind
would write it.
(-1=3|#{.d)}."1 ,. _ _ 2{. (($,)~#,3,~3%~#@{.) (>.&.(%&3)#{. d) {."_1 d
-nejshulx
effbpl-z-
-sxe--bj-
gu-qniztn
h-zl-hkly
snjteajja
There's surely many other ways, but I'm stopping now.
Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm