comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » subseting a 3D array based on values from a 2D array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
subseting a 3D array based on values from a 2D array [message #87484] Fri, 07 February 2014 05:25 Go to next message
eva.ivits-wasser is currently offline  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 Go to previous messageGo to next message
David Fanning is currently offline  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 Go to previous messageGo to next message
eva.ivits-wasser is currently offline  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 Go to previous message
David Fanning is currently offline  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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: matchdelim
Next Topic: IDL_IDLBridge, spawn, and sftp, oh my!

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:14:23 PDT 2025

Total time taken to generate the page: 0.00583 seconds