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

Home » Public Forums » archive » Re: array problems
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
Re: array problems [message #61292] Fri, 11 July 2008 12:59 Go to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
jschwab@gmail.com wrote:
> On Jul 11, 2:36 pm, "David Sheerin" <davidshee...@btinternet.com>
> wrote:
>> Hi All
>> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
>> to expand it to include the mean between each value like [(0+a)/2, a,
>> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2]. Is there any
>> elegant way of doing this without having to resort to clunky for loops?
>>
>> I also would like to repeat this action on the resulting vector.
>>
>> Thanks for any tips
>>
>> David
>
> Or, even better, just use interpol.
>
> if
> array = [a, b, c, b, a]
> then
> output = interpol(array, 9)

kudos for the oneliner!

Paolo

> is your desired result
>
> Josiah
Re: array problems [message #61293 is a reply to message #61292] Fri, 11 July 2008 12:26 Go to previous messageGo to next message
jschwab@gmail.com is currently offline  jschwab@gmail.com
Messages: 30
Registered: December 2006
Member
On Jul 11, 2:36 pm, "David Sheerin" <davidshee...@btinternet.com>
wrote:
> Hi All
> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
> to expand it to include the mean between each value like [(0+a)/2, a,
> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2]. Is there any
> elegant way of doing this without having to resort to clunky for loops?
>
> I also would like to repeat this action on the resulting vector.
>
> Thanks for any tips
>
> David

Or, even better, just use interpol.

if
array = [a, b, c, b, a]
then
output = interpol(array, 9)
is your desired result

Josiah
Re: array problems [message #61294 is a reply to message #61293] Fri, 11 July 2008 12:02 Go to previous messageGo to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
David Sheerin wrote:
> Hi All
> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
> to expand it to include the mean between each value like [(0+a)/2, a,
> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2]. Is there any
> elegant way of doing this without having to resort to clunky for loops?
>
> I also would like to repeat this action on the resulting vector.
>
> Thanks for any tips
>
> David
>
>

Hi,
1) get your "average".
nbEntries = n_elements(data)
avg = (data + shift(data,-1)) /2.0
2)add the 1st entry and correct the last entry:
avg = [data[0] / 2.0,avg]
avg[nbEntries] = data[nbEntries-1] / 2.0
3)create the new array by coping each original array, with a "step" of 2
cells betweens two values from the same original array
newData = fltarr(nbEntries*2+1)
nnewData[1:nbEntries*2:2] = data
newData[0:nbEntries*2:2] = avg

Jean
Re: array problems [message #61295 is a reply to message #61294] Fri, 11 July 2008 12:20 Go to previous messageGo to next message
jschwab@gmail.com is currently offline  jschwab@gmail.com
Messages: 30
Registered: December 2006
Member
On Jul 11, 2:36 pm, "David Sheerin" <davidshee...@btinternet.com>
wrote:
> Hi All
> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
> to expand it to include the mean between each value like [(0+a)/2, a,
> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2]. Is there any
> elegant way of doing this without having to resort to clunky for loops?
>
> I also would like to repeat this action on the resulting vector.
>
> Thanks for any tips
>
> David

You can do this in a few lines with a combination of rebin and shift.

;; Take only the first section of the array
half = [a, b, c]

;; use rebin with the sample keyword to duplicate your values
;; this gives [a, a, b, b, c, c]
n = n_elements(half)
doubled = rebin(half, 2 * n, /sample)

;; now use shift to combine and average, and drop the last element
extended = ((doubled + shift(doubled, -1)) / 2.0)[0:2*n-2]

;; now you can use reverse() and array concatenation to do back
;; to the full palindromic array

Josiah
Re: array problems [message #61296 is a reply to message #61294] Fri, 11 July 2008 12:03 Go to previous messageGo to next message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Jul 11, 1:36 pm, "David Sheerin" <davidshee...@btinternet.com>
wrote:
> Hi All
> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
> to expand it to include the mean between each value like [(0+a)/2, a,
> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2].  Is there any
> elegant way of doing this without having to resort to clunky for loops?
>
> I also would like to repeat this action on the resulting vector.
>
> Thanks for any tips
>
> David

Sounds like you want to look into SHIFT()
Re: array problems [message #61366 is a reply to message #61293] Mon, 14 July 2008 08:16 Go to previous messageGo to next message
Bob[3] is currently offline  Bob[3]
Messages: 60
Registered: December 2006
Member
On Jul 11, 3:26 pm, "jsch...@gmail.com" <jsch...@gmail.com> wrote:
> On Jul 11, 2:36 pm, "David Sheerin" <davidshee...@btinternet.com>
> wrote:
>
>> Hi All
>> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
>> to expand it to include the mean between each value like [(0+a)/2, a,
>> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2].  Is there any
>> elegant way of doing this without having to resort to clunky for loops?
>
>> I also would like to repeat this action on the resulting vector.
>
>> Thanks for any tips
>
>> David
>
> Or, even better, just use interpol.
>
> if
> array = [a, b, c, b, a]
> then
> output = interpol(array, 9)
> is your desired result
>
> Josiah

Don't forget to add in the first and last elements.
output2 = [output[0]/2, output, output[0]/2] - or similar.
Re: array problems [message #61417 is a reply to message #61366] Tue, 15 July 2008 12:24 Go to previous message
David Sheerin is currently offline  David Sheerin
Messages: 4
Registered: April 1999
Junior Member
Great - this is an elegant solution...

Thanks!


"Bob Crawford" <Snowman42@gmail.com> wrote in message
news:8d9523e8-2690-4408-89fb-3f2caed198be@25g2000hsx.googleg roups.com...
On Jul 11, 3:26 pm, "jsch...@gmail.com" <jsch...@gmail.com> wrote:
> On Jul 11, 2:36 pm, "David Sheerin" <davidshee...@btinternet.com>
> wrote:
>
>> Hi All
>> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would
>> like
>> to expand it to include the mean between each value like [(0+a)/2, a,
>> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2]. Is there any
>> elegant way of doing this without having to resort to clunky for loops?
>
>> I also would like to repeat this action on the resulting vector.
>
>> Thanks for any tips
>
>> David
>
> Or, even better, just use interpol.
>
> if
> array = [a, b, c, b, a]
> then
> output = interpol(array, 9)
> is your desired result
>
> Josiah

Don't forget to add in the first and last elements.
output2 = [output[0]/2, output, output[0]/2] - or similar.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Where O Where Di My Pointer Go?
Next Topic: Re: Where O Where Di My Pointer Go?

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

Current Time: Wed Oct 08 18:40:04 PDT 2025

Total time taken to generate the page: 0.00622 seconds