array dimensions and subscripts [message #39201] |
Tue, 27 April 2004 07:46 |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
Hi all,
I have a 3d data array A (n_columns, n_rows, n_data) where columns and
rows make up an image and for each pixel in the image I recorded n_data
different data values.
Then I have a 1d array B with n_data entries, and I want to subtract B
from A such that for each element in A, the element from B in the
corresponding data channel is subtracted. Obviously, A-B won't work. I
can imagine two ways:
1. For loop
result = fltarr(n_columns, n_rows, n_data) ;; initialize
for i=0, n_data-1 do results[*, *, i] = A[*, *, i] - B[i]
2. Blowing up B to 3d (which I can't manage to do without a for loop
either)
B1 = fltarr(n_column, n_rows, n_data)
for i=0, n_data-1 do B1[*, *, i] = B[i]
result = A - B1
But these solutions don't seem very elegant and efficient to me. Is
there any way to make it work with a single array operation using the *
subscript, or something similar?
Thanks for your help,
Benjamin
|
|
|