Re: Using where() on slices of data cubes [message #68342 is a reply to message #68335] |
Tue, 20 October 2009 06:20   |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
Well it works, so I can't knock it that much :) I had resorted to
using a for loop :(
On Oct 20, 9:03 am, David Fanning <n...@dfanning.com> wrote:
> Conor writes:
>> I feel like this should be an easy one, but I've never quite figured
>> it out. Let's say I got a data cube and I want to do something on
>> just a slice of it, say I want to turn certain values in a column into
>> something else:
>
>> w = where( cube[1,*,*] lt 0 )
>
>> It seems like you should be able to do something like this:
>
>> cube[1,w] = 1e24
>
>> But that doesn't work... Somehow I can't quite figure out the right
>> way to do this.
>
> It *seems* like there should be a simple way to do this,
> but if there is, I haven't found it. What would make
> sense to me is this:
>
> (cube[1,*,*])[w] = 1e24
>
> But this gives the error message that you can't store into
> a temporary variable. (The ol' pass by reference/pass by value
> thing, I suppose.)
>
> I have always resorted to making a subset of the data, like
> this:
>
> sub = cube[1,*,*]
> w = where(sub lt 0)
> sub[w] = 1e24
> cube[1,*,*] = sub
>
> Not at all elegant, I admit. :-(
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|