0

I am working on a port of some IDL code to Python (3.7). I have a translation working which uses whatever direct Python alternatives are available, and supplementing what I can with idlwrap. In an effort to eliminate legacy IDL functions from the code, I am looking for an alternative to ARRAY_INDICES(). Right now, I have simply translated the entire function directly and import it on its own. I've spent a good deal of time trying to understand exactly what it does, and even after translating it verbatim, it is still unclear to me, which makes coming up with a simple Python solution challenging.

The good news is I only need it to work with one specific set of arrays whose shapes wont change. An example of the code that will be run follows:

temp = np.sum(arr, axis=0)

goodval = idlwrap.where(temp > -10)

ngood = goodval.size

arr2 = np.zeros_like(arr)

for i in range(0, ngood - 1):

    indices = array_indices(arr2, goodval[i])

    #use indices for computation
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • 1
    Are you asking what ARRAY_INDICES does? IDL's WHERE function returns a 1-dimension index into an array, even if the array is multi-dimensional. If, for some reason, you need to know the row or column (or equivalent in higher dimensions), then you can convert the 1-dimensional indices to multi-dimensional indices using ARRAY_INDICES. NumPy's WHERE function returns multi-dimensional indices top begin with. – mgalloy Jan 28 '20 at 18:32
  • The other way around one could ask how to convert the scalar index returned by IDL's `WHERE` for an n-dimensional array to the index tuple used to index numpy's `ndarray` – FObersteiner Jan 29 '20 at 08:54
  • Side note: are you aware that you'll only loop through integers from 0 to `ngood - 2`? `range()` is exclusive of the second argument. This is a difference with how loops in IDL are often written. – sappjw Jan 29 '20 at 15:18
  • @mgalloy Yes that is essentially what I was looking for. I figured there must be a simple explanation for the whole thing. I believe I can make that work for me now. – messenger Jan 29 '20 at 21:45
  • @sappjw Yes thank you.. I find that I keep missing simple things like this while working on translation. Appreciated. – messenger Jan 29 '20 at 21:46

0 Answers0