#
and ##
operate on 2D IDL arrays interpreted as mathematical matrices and
vectors. (I will try to keep this distinction between the IDL
variable type and the mathematical entities.) The two operators use
different conventions for the index order. The #
operator
uses (row, column) order, while the ##
operator uses
(column, row) order. Simple, right? Well, this confused me a bit and
apparently also others
(see thread
in comp.lang.idl-pwvave).
Part of my own confusion, I realized, was the way the matrices were
printed. The IDL print
command can print arrays
but it is apparently not designed to print matrices! (I'll make
a distinction between the IDL array variable type and the concept of
matrices and vectors in linear algebra.) For one thing,
matrices need to be printed differently depending on whether they are
meant to be interpreted by the #
operator or
the ##
operator. Not taking the operator into account
will only result in explanations such as
this,
where, even when presented as a matrix with brackets and all,
an array was simply printed in the order the
IDL print
command would. For the matrix operations to
make sense, the matrices need to be printed in the way they are to be
interpreted.
PrintMatrix
procedure
(printmatrix.pro
) prints a
matrix M and takes the operator as an optional keyword
(with ##
as the default) and prints the matrix
accordingly.
When printing matrices with PrintMatrix
, the operations
and conventions make sense. In the frames below I show a script and
its journal
output, where I define two arrays, A and B,
and print them as well as their matrix products. The matrix dimensions
match the way they are supposed to. For both operators!
Note that in the two examples the IDL arrays are the same but their interpretation as matrices differ.
Because IDL removes trailing dimensions if they are of length 1, vectors add some more uncertainty. But when printed correctly, also they make sense.
LA_SVD
. This routine interprets the arrays as matrices
using the ##
convention.
#
convention for input and the ##
convention for output! Maybe the best way of thinking about it is
that it should be called with the transpose of the matrix we want
to factorize.