Re: adding "placeholders" to an array [message #48967] |
Tue, 06 June 2006 15:12 |
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  |
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  |
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
|
|
|