Reducing an array. [message #32280] |
Mon, 30 September 2002 15:23  |
Joe[3]
Messages: 2 Registered: September 2002
|
Junior Member |
|
|
Hi- I'm somewhat new to IDL and was wondering what the most effiecient way
is to 'OR' all the elements of an array together resulting in a scalar
value. I'm hoping IDL has a built-in way of doing this rather than using a
FOR-LOOP. Similar to how IDL has the TOTAL function which sums all the
elements of an array together. I've used other languagues which allow you
to 'reduce' arrays to a scalar using an arbitrary function (i.e. Python's
reduce function).
What I am doing is taking a lot of integer data which is either 0's or 1's
and compressing it into the bits of 64-bit unsigned integers. Here is a bit
of sample code:
data = [1,0,0,0,1,1,1,0,1,0,1,0,0, ... , 0, 1, 0, 1] ; bunch of data, assume
# of elements is multiple of 64
shifts = reverse(indgen(n_elements(data))) MOD 64
compressed_data = ishft(data,shifts)
; here is where I want to take the compressed_data array and make it into a
; bunch (n_elements(data)/64, to be exact) of unsigned 64-bit integers by
OR'ing
; every 64 elements of compressed data togeter
Thanks for any help,
Joe
|
|
|