X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 04 Jan 2019 05:01 PM by  Jim Uba
vector operation in function arguments
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Ed Hartouni



New Member


Posts:
New Member


--
25 Nov 2018 11:55 PM
    I am running IDL 8.5.1 on Mac OS X 10.13.6

    the problem:
    IDL> print, abs(a-b)
    1
    IDL> print, abs(a-b[0])
    1 0 1 2 1 0 1 2 1 0 1 2
    IDL> print,b
    2
    IDL> a=[1,2,3,4,1,2,3,4,1,2,3,4]
    IDL> b=[1,2,3,4]
    IDL> print, abs(a-b[1])
    1 0 1 2 1 0 1 2 1 0 1 2
    IDL> b=reform(b[1])
    IDL> print, abs(a-b)
    1
    IDL> print, abs(a-b[0])
    1 0 1 2 1 0 1 2 1 0 1 2
    IDL> help,b
    B INT = Array[1]
    IDL>

    previously the abs(a-b) line worked the same as the abs(a-b[0]) line.

    Not sure why or how this has changed.

    Any ideas?
    thanks

    Jim Uba



    New Member


    Posts:81
    New Member


    --
    04 Jan 2019 05:01 PM
    If B is an array of numbers, or even a single element array, then B[0] will be a scalar. If you subtract an array of numbers from a different sized array of numbers, then the result is an array with the element count of the smaller array.

    However, if you subtract a scalar from an array then the result will be an array of the same size as the array in the expression.

    For example:

    IDL> a = indgen(10)
    IDL> b = indgen(3)
    IDL> c = a-b
    IDL> help, c
    C INT = Array[3]
    IDL> help, b[1]
    <Expression> INT = 1
    IDL> help, [b[1]]
    <Expression> INT = Array[1]
    IDL> help, a-b[1]
    <Expression> INT = Array[10]
    IDL> help, a-[b[1]]
    <Expression> INT = Array[1]

    I'm not aware of any recent changes in IDL regarding this behavior.

    I hope this can help!
    -Jim (HGS)
    You are not authorized to post a reply.