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

Home » Public Forums » archive » Re: Adding or deduct values in a ARRAY
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Adding or deduct values in a ARRAY [message #52159 is a reply to message #52158] Fri, 19 January 2007 05:45 Go to previous messageGo to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Erik wrote:
> Hey Wox,
>
> Thanks for your reply.
>
> I've tried ARR1[0,*] -10 and ARR1[0,*,*] -10 (both the same)
>
> Then I got a float array with dimensions [1, 4]
>
> 83.0000
> 83.0000
> 141.000
> 141.000
>
> These are the good values, however as stated before I want the array to
> stay a [3,4] array with the old Y and Z values still stored in it.
>

Hello Erik,

I think you might have missed the subtle syntax that Wox posted. It
both reduced the first column by 10 AND assigned the result to the
original column.

IDL> arr1 = FINDGEN(3,4)
IDL> print, arr1
0.00000 1.00000 2.00000
3.00000 4.00000 5.00000
6.00000 7.00000 8.00000
9.00000 10.0000 11.0000

the following is the assignment that reduces the first column by 10,
this is the "traditional" way to do it and it is pretty clear

IDL> arr1[0,*] = arr1[0,*] - 10
IDL> print, arr1
-10.0000 1.00000 2.00000
-7.00000 4.00000 5.00000
-4.00000 7.00000 8.00000
-1.00000 10.0000 11.0000

and the following syntax does the same thing (note the "-=") even though
it is a little less obvious until you get used to it

IDL> arr1[0,*] -= 10
IDL> print, arr1
-20.0000 1.00000 2.00000
-17.0000 4.00000 5.00000
-14.0000 7.00000 8.00000
-11.0000 10.0000 11.0000

most likely you have been assigning the result of the subtraction to a
new variable which assigns the new variable the (changed) value of the
first column

IDL> arr2 = arr1[0,*] - 10
IDL> print, arr2
-30.0000
-27.0000
-24.0000
-21.0000

Does the help?
Ben
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Adding or deduct values in a ARRAY
Next Topic: Avoiding loop stats

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

Current Time: Fri Oct 10 23:17:50 PDT 2025

Total time taken to generate the page: 0.32302 seconds