subseting a 3D array based on values from a 2D array [message #87484] |
Fri, 07 February 2014 05:25  |
eva.ivits-wasser
Messages: 8 Registered: October 2011
|
Junior Member |
|
|
Hi everyone,
I have a 2D array (A) with dimensions of [ns,nl] (where ns=number of columns and nl=number of lines) and a 3D array (B) with dimensions of [ns,nl,nb] (where nb=number of bands). A is a classification image whereas B is a time-series, both have the same number of samples and lines.
I'd need to find a certain value in A, let's say 100 (which occurs several times) and then I want to subset those elements of B which "overlaps" with A, i.e. have the same position as A.
I've tried the where function but that gives me the one dimensional subscript of A and I don't quite manage to index B based on this subscript...
I've tried array_indices but did not get further with that either.
Any suggestions please?
Thanks,
Eva
|
|
|
Re: subseting a 3D array based on values from a 2D array [message #87485 is a reply to message #87484] |
Fri, 07 February 2014 05:37   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
eva.ivits-wasser@ext.jrc.ec.europa.eu writes:
> I have a 2D array (A) with dimensions of [ns,nl] (where ns=number of columns and nl=number of lines) and a 3D array (B) with dimensions of [ns,nl,nb] (where nb=number of bands). A is a classification image whereas B is a time-series, both have the same number of samples and lines.
> I'd need to find a certain value in A, let's say 100 (which occurs several times) and then I want to subset those elements of B which "overlaps" with A, i.e. have the same position as A.
>
> I've tried the where function but that gives me the one dimensional subscript of A and I don't quite manage to index B based on this subscript...
>
> I've tried array_indices but did not get further with that either.
>
> Any suggestions please?
dims = Size(A, /Dimenisions)
indices = Where(A ...)
colrow = Array_Indices(dims, indices, /Dimensions)
cols = colrow[0,*]
rows = colrow[1,*]
valuesIwant = B[cols, rows, *]
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: subseting a 3D array based on values from a 2D array [message #87486 is a reply to message #87485] |
Fri, 07 February 2014 06:11   |
eva.ivits-wasser
Messages: 8 Registered: October 2011
|
Junior Member |
|
|
YES, EXACTLY, THIS IS IT, IT WORKS!
THANKS A LOT (*10000000000)
EVA
Il giorno venerdì 7 febbraio 2014 14:37:36 UTC+1, David Fanning ha scritto:
> eva.ivits-wasser@ext.jrc.ec.europa.eu writes:
>
>
>
>> I have a 2D array (A) with dimensions of [ns,nl] (where ns=number of columns and nl=number of lines) and a 3D array (B) with dimensions of [ns,nl,nb] (where nb=number of bands). A is a classification image whereas B is a time-series, both have the same number of samples and lines.
>
>> I'd need to find a certain value in A, let's say 100 (which occurs several times) and then I want to subset those elements of B which "overlaps" with A, i.e. have the same position as A.
>
>>
>
>> I've tried the where function but that gives me the one dimensional subscript of A and I don't quite manage to index B based on this subscript...
>
>>
>
>> I've tried array_indices but did not get further with that either.
>
>>
>
>> Any suggestions please?
>
>
>
> dims = Size(A, /Dimenisions)
>
> indices = Where(A ...)
>
> colrow = Array_Indices(dims, indices, /Dimensions)
>
> cols = colrow[0,*]
>
> rows = colrow[1,*]
>
> valuesIwant = B[cols, rows, *]
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: subseting a 3D array based on values from a 2D array [message #87487 is a reply to message #87486] |
Fri, 07 February 2014 07:11  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
eva.ivits-wasser@ext.jrc.ec.europa.eu writes:
>
> YES, EXACTLY, THIS IS IT, IT WORKS!
>
> THANKS A LOT (*10000000000)
>
> EVA
Well, it's not cash, but it's *something*! ;-)
Cheers,
David
P.S. It's been well below 0 here in Colorado this week. The beer has
nearly frozen and Coyote has had to switch to schnapps. But, effusive
praise makes us warm, too. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|