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

Home » Public Forums » archive » 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
array [message #90543] Mon, 09 March 2015 02:27 Go to next message
8sushil is currently offline  8sushil
Messages: 2
Registered: March 2015
Junior Member
how can i print the location in the matrix knowing the value in that location.
Re: array [message #90544 is a reply to message #90543] Mon, 09 March 2015 02:50 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, March 9, 2015 at 10:27:39 AM UTC+1, 8sushil wrote:
> how can i print the location in the matrix knowing the value in that location.

User the where() function as described here:
http://exelisvis.com/docs/WHERE.html

The result is a 1D location. If your matrix/array is 2D and you *need* a 2D result, then you can use array_indices():
http://exelisvis.com/docs/ARRAY_INDICES.html

If the value you're looking for is myValue and the matrix/array is myArray, then you can use this:

position = where(myValue eq myArray, cnt)
print, 'my 1D position is: ', position
print, 'my 2D position is: ', array_indices(myArray, position)

Make sure you check how to use the cnt result (-1 if not found!). This should get you going. If you're looking for floats, it can be a bit more tricky.

Cheers,
Helder
Re: array [message #90545 is a reply to message #90544] Mon, 09 March 2015 11:11 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
>> how can i print the location in the matrix knowing the value in that location.
>
> User the where() function as described here:
> http://exelisvis.com/docs/WHERE.html

Also, note that if your array is sorted monotonically, VALUE_LOCATE will do it much faster.

(yes, Jeremy's back and proselytizing about VALUE_LOCATE)

-Jeremy.
Re: array [message #90546 is a reply to message #90545] Mon, 09 March 2015 11:53 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
Since you're the Value_locate guy, can it be used with 2d arrays? If so, how is monotonic defined in these cases? By using 1d indexes for a 2d array?
I don't have pc access at the moment to check myself, so I thought I would ask the guru ;-)
Sorry if the question has an obvious answer.
And in case of a 2d array, when does one end up with a monotonic 2d array (however this is defined)?

Thanks,
Helder
Re: array [message #90548 is a reply to message #90546] Mon, 09 March 2015 12:47 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
> Since you're the Value_locate guy, can it be used with 2d arrays? If so, how is monotonic defined in these cases? By using 1d indexes for a 2d array?

Yes, exactly -- it needs to be monotonic with respect to 1D indices.


> And in case of a 2d array, when does one end up with a monotonic 2d array (however this is defined)?

For example:

q = indgen(N1, N2)

gives you an array that is monotonic as far as Value_Locate is concerned. Also, I will sometimes create a 2D array that is monotonic by stacking together individually-monotonic 1D arrays with offsets in the second dimension for the express purpose of using Value_Locate on it. For example, if W is an N1 x N2 array where each W[*,i] is sorted, then you can create a monotonic 2D array is follows:

; in order to make the array monotonic, we need to add an offset to
; each row that will ensure that the minimum value for every subsequent
; row is pushed to being greater than the maximum value of each previous
; row. The following example will technically only work for non-negative W
; and for either integers or not-too-large floats, but can be generalized.
offset = max(W)+1
Wdimen = size(W, /dimen)
; create an N1 x N2 array that adds an appropriate increment to each row
W2 = W + rebin(offset * lindgen(1, Wdimen[1]), Wdimen, /sample)

-Jeremy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Subsetting a multiple images using multiple envi vector files (EVFs)
Next Topic: Geopotential height gradient

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

Current Time: Wed Oct 08 09:16:16 PDT 2025

Total time taken to generate the page: 0.00442 seconds