|
Re: *replicate* but with arrays [message #26616 is a reply to message #26615] |
Mon, 10 September 2001 17:41  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
aqueous0123@yahoo.com (aqueous) writes:
> If I have array a[3,50] and array b[3], how do I fill all rows of a
> with the row vector b? For example, what I want to do is
>
> a = intarr(3,50)
> b = [6,5,4]
> a[0:2,*] = b ;or a[*,*] = b
>
> a should now look like
>
> [6,5,4]
> [6,5,4]
> [6,5,4]
> [6,5,4]
> ...
>
> I thought I could use replicate or makearray, like..
> a = REPLICATE(b, n_elements(b), 50)
> or
> a = MAKE_ARRAY(n_elements(b), 50, /INTEGER, VALUE= b)
Mark and Pavel's responses are fine and dandy. I use REBIN all the
time to do exactly the kind of thing you are after. However, if you
just want a REPLICATE work-alike, then I might suggest the function
CMREPLICATE, available from my web page.
It is standalone and works just like you'd expect, even simpler
actually since you don't specify n_elements(b):
IDL> b = [6,5,4]
IDL> a = cmreplicate(b, 50)
IDL> help, a
A INT = Array[3, 50]
For numeric arrays it uses rebin so it is just as efficient as using
REBIN yourself. However it also works generally on structure arrays
and strings, which are processed differently.
Good luck,
Craig
http://cow.physics.wisc.edu/~craigm/idl/idl.html (under Arrays)
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: *replicate* but with arrays [message #26618 is a reply to message #26615] |
Mon, 10 September 2001 15:15  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
Try
a = rebin(b, 3, 50)
Cheers,
Pavel
aqueous wrote:
>
> If I have array a[3,50] and array b[3], how do I fill all rows of a
> with the row vector b? For example, what I want to do is
>
> a = intarr(3,50)
> b = [6,5,4]
> a[0:2,*] = b ;or a[*,*] = b
>
> a should now look like
>
> [6,5,4]
> [6,5,4]
> [6,5,4]
> [6,5,4]
|
|
|
|