X
82 Rate this article:
No rating

Internal: Three-dimensional (3D) matrix multiplication

Anonym

The array multiply operator '#' only multiplies at the first level of an array even though no error is generated.
The following lines are an example:

IDL> a = FINDGEN(3, 3, 3)
IDL> b = FINDGEN(3, 3, 3)
IDL> c = b # a
IDL> PRINT, c
15.0000 18.0000 21.0000
42.0000 54.0000 66.0000
69.0000 90.0000 111.000
IDL> HELP, c
C FLOAT = Array(3, 3)


To access the third dimension with the '#' operator you must explicitly state these levels as follows

IDL> c = FLTARR(3, 3, 3)
IDL> c[*, *, 0] = b[*, *, 0] # a[*, *, 0]
IDL> c[*, *, 1] = b[*, *, 1] # a[*, *, 1]
IDL> c[*, *, 2] = b[*, *, 2] # a[*, *, 2]
IDL> PRINT, c
15.0000 18.0000 21.0000
42.0000 54.0000 66.0000
69.0000 90.0000 111.000

366.000 396.000 426.000
474.000 513.000 552.000
582.000 630.000 678.000

1203.00 1260.00 1317.00
1392.00 1458.00 1524.00
1581.00 1656.00 1731.00