Re: scalar system variable as single element array [message #80165] |
Sun, 13 May 2012 23:31 |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den söndagen den 13:e maj 2012 kl. 22:00:31 UTC+2 skrev fawltyl...@gmail.com:
> Hi guys,
>
> the IDL help says that a scalar can be considered a single element array. So why is the following expression failing?
>
> IDL> help, !pi[0]
> % Expression must be an array in this context: !PI.
> % Execution halted at: $MAIN$
>
> Is it a bug or feature :-)
>
> regards,
> Lajos
This works with variables but !pi is not a variable. Think of it as a constant, like the number 2:
IDL> a=!pi
IDL> help,2,!pi,a
<Expression> INT = 2
<Expression> FLOAT = 3.14159
A FLOAT = 3.14159
IDL> help,a[0]
<Expression> FLOAT = 3.14159
IDL> help,(2)[0],(!pi)[0]
<Expression> INT = 2
<Expression> FLOAT = 3.14159
|
|
|
Re: scalar system variable as single element array [message #80166 is a reply to message #80165] |
Sun, 13 May 2012 23:23  |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
On Monday, May 14, 2012 1:58:52 AM UTC+2, alx wrote:
> Because, in IDL, as far as I know, scalar and array are two different
> things!
As I wrote scalars can be considered as single element array (in subscript expressions). From IDL help:
Notice that because a scalar can be considered a single element array, subscripting a scalar with -1 (indicating the last element of the array) is equivalent to subscripting the scalar with 0 (indicating the first element of the array). For example:
scalar = 3
PRINT, scalar, scalar[0], scalar[-1]
IDL prints:
3 3 3
You can even write scalar[0, 0:0, *, -1:-1:1]. Now replace scalar with !PI.
regards,
Lajos
|
|
|
Re: scalar system variable as single element array [message #80172 is a reply to message #80166] |
Sun, 13 May 2012 16:58  |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
On 13 mai, 22:00, fawltylangu...@gmail.com wrote:
> Hi guys,
>
> the IDL help says that a scalar can be considered a single element array. So why is the following expression failing?
>
> IDL> help, !pi[0]
> % Expression must be an array in this context: !PI.
> % Execution halted at: $MAIN$
>
> Is it a bug or feature :-)
>
> regards,
> Lajos
>
>
Because, in IDL, as far as I know, scalar and array are two different
things!
!pi is not an array, but [!pi] is. If a scalar could be considered as
a single element array, the IDL implicit dimension rule would fail:
IDL> help,indgen(10) + !pi
<Expression> FLOAT = Array[10]
IDL> help,indgen(10) + [!pi]
<Expression> FLOAT = Array[1]
Conversely, a single element array cannot be considered as a scalar,
unless you explicitely address it:
IDL> help,indgen(10) + ([!pi])[0]
<Expression> FLOAT = Array[10]
Cheers,
alx.
|
|
|