Pascal - at first glance, this does look a lot like your earlier query.

However,

  dot =: 4 : ' x +/ . * y'
  qb0 =: ,. 1 0
  qb1 =: ,. 0 1
  pauliX =: 2 2 $ (0 1 1 0)
  pauliX dot qb0 NB. Works
0
1
  pauliX dot qb1 NB. Also works
1
0
  pauliX dot qb0,.qb1 NB. Also works
0 1
1 0
  NB. Selecting columns:
  ]m =: 2 5 $ i. 10
0 1 2 3 4
5 6 7 8 9
  2 3{"1 m
2 3
7 8
  pauliX dot m
5 6 7 8 9
0 1 2 3 4

  NB. Updating columns:
  ix=. 2 3 NB. Arbitrary columns to update
  pauliX dot ix{"1 m
7 8
2 3
  ]m=. (pauliX dot ix{"1 m) ix}"1 m
0 1 7 8 4
5 6 2 3 9

  NB. This is functionally the same as
  m=. i. 2 5
  ]m=. (|.ix{"1 m) ix}"1 m
0 1 7 8 4
5 6 2 3 9

Is matrix multiplication simply used to swap elements around like this all
the time in your problems?  Or are there more general uses of it?

I'm asking because I've seen this sort of structural re-arrangement done
with matrix multiply by booleans before.  I'm wondering if this is because
there's no direct way to re-position elements of an array in conventional
mathematics, so we resort to this kind of "trick" to accomplish it, or is
there another reason?

--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to