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

Home » Public Forums » archive » Re: adding "placeholders" to an array
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: adding "placeholders" to an array [message #48967] Tue, 06 June 2006 15:12
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
pimpk24@hotmail.com writes:


> I was wondering if there is a way to change the dimesions of an
> existing array and to hardwire the new values. It seems that the rebin
> and reform functions only add values by interpolation and nearest
> sampling. I want to predeterming what the new value will be
>
> e.g. Given a random vector, how can I add dimensions of all zero values
>
> 1 4 6 7 8 354 42345
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0

The answer to this problem can be found in the Array Concatenation
and Dimensional Juggling Tutorials:

http://www.dfanning.com/tips/array_concatenation.html
http://www.dfanning.com/tips/rebin_magic.html

For example:

IDL> a = [ 1, 4, 6, 7, 8, 354, 42345L]
IDL> b = LonArr(7,2)
IDL> c = [[a],[b]]
IDL> Print, c
1 4 6 7 8 354 42345
0 0 0 0 0 0 0
0 0 0 0 0 0 0

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: adding "placeholders" to an array [message #48968 is a reply to message #48967] Tue, 06 June 2006 15:02 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
pimpk24@hotmail.com wrote:
> I was wondering if there is a way to change the dimesions of an
> existing array and to hardwire the new values. It seems that the rebin
> and reform functions only add values by interpolation and nearest
> sampling. I want to predeterming what the new value will be
>
> e.g. Given a random vector, how can I add dimensions of all zero values
>
> 1 4 6 7 8 354 42345
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0
>
>
> thanks in advance
>

You can't change the size of the array without recreating and copying:

IDL> v = [1L, 4L, 6L, 7L, 8L, 354L, 42345L]
IDL> newv = lonarr(7, 3)
IDL> newv[0, 0] = reform(v, 7, 1)
IDL> print, newv
1 4 6 7 8 354
42345
0 0 0 0 0 0
0
0 0 0 0 0 0
0

Mike
--
www.michaelgalloy.com
Re: adding "placeholders" to an array [message #48969 is a reply to message #48968] Tue, 06 June 2006 14:53 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
pimpk24@hotmail.com wrote:
> Hello,
>
> I was wondering if there is a way to change the dimesions of an
> existing array and to hardwire the new values. It seems that the rebin
> and reform functions only add values by interpolation and nearest
> sampling. I want to predeterming what the new value will be
>
> e.g. Given a random vector, how can I add dimensions of all zero values
>
> 1 4 6 7 8 354 42345
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0
>
>
> thanks in advance
>

Brute force methods:


IDL> x=[1, 4, 6, 7, 8, 354, 42345]
IDL> n=n_elements(x)
IDL> print, [[x],[make_array(n,2,value=0)]]
1 4 6 7 8 354 42345
0 0 0 0 0 0 0
0 0 0 0 0 0 0

Or, you could use LONARR instead:

IDL> print, [[x],[lonarr(n,2)]]
1 4 6 7 8 354 42345
0 0 0 0 0 0 0
0 0 0 0 0 0 0

but the use of MAKE_ARRAY means you can change the "placeholder" value to something other
than zero if you wanted.

paulv

p.s. I'm sure there's a more elegant method than those above. :o)

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: .Reset_Session in a script
Next Topic: iTool identifiers

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

Current Time: Wed Oct 08 22:09:57 PDT 2025

Total time taken to generate the page: 0.55941 seconds