Re: more for-loops vs. arrays [message #19337] |
Wed, 08 March 2000 00:00 |
reardonb
Messages: 16 Registered: December 1999
|
Junior Member |
|
|
Thanks, Everyone!
Perhaps I should read the documentation more closely next time.
-Brian
In article <8a5vol$pa1$1@nnrp1.deja.com>,
reardonb@my-deja.com wrote:
> I also have a For-loop vs. array question.
> I want to fill an array with a random sequence of
> 1's and 0's. This works:
>
> array1 = intarr(5,4)
> for I=0,4-1 do begin
> for II=0,5-1 do begin
> array1[II,I] = round(randomu(s))
> endfor
> endfor
>
> but can I do it without for loops?
> Thanks.
> -Brian
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
|
|
|
Re: more for-loops vs. arrays [message #19339 is a reply to message #19337] |
Wed, 08 March 2000 00:00  |
Steve Hartmann
Messages: 21 Registered: March 2000
|
Junior Member |
|
|
reardonb@my-deja.com wrote:
> I also have a For-loop vs. array question.
> I want to fill an array with a random sequence of
> 1's and 0's. This works:
>
> array1 = intarr(5,4)
> for I=0,4-1 do begin
> for II=0,5-1 do begin
> array1[II,I] = round(randomu(s))
> endfor
> endfor
>
> but can I do it without for loops?
> Thanks.
> -Brian
>
How about this?
array1 = round( randomu(s,5,4) )
-Steve
|
|
|
Re: more for-loops vs. arrays [message #19340 is a reply to message #19337] |
Wed, 08 March 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Brian Reardon (reardonb@my-deja.com) writes:
> I also have a For-loop vs. array question.
> I want to fill an array with a random sequence of
> 1's and 0's. This works:
>
> array1 = intarr(5,4)
> for I=0,4-1 do begin
> for II=0,5-1 do begin
> array1[II,I] = round(randomu(s))
> endfor
> endfor
>
> but can I do it without for loops?
My Goodness! Here is one even *I* know how to do. :-)
Print, Floor( RandomU(seed, 5, 4) * 2 )
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: more for-loops vs. arrays [message #19341 is a reply to message #19337] |
Wed, 08 March 2000 00:00  |
Ben Tupper
Messages: 186 Registered: August 1999
|
Senior Member |
|
|
reardonb@my-deja.com wrote:
> I also have a For-loop vs. array question.
> I want to fill an array with a random sequence of
> 1's and 0's. This works:
>
> array1 = intarr(5,4)
> for I=0,4-1 do begin
> for II=0,5-1 do begin
> array1[II,I] = round(randomu(s))
> endfor
> endfor
>
> but can I do it without for loops?
>
Hello,
I think so... try the following
Arr = RandomU(Seed, 5,4)
Arr = Arr * (Arr GT 0.5)
You could actually shorten this to ...
Arr = RandomU(Seed,5,4) GT 0.5
Be sure to check of the earlier discussion about the random number
generation in IDL , I think it starts with Fun with Random Numbers.
Ben
--
Ben Tupper
Bigelow Laboratory for Ocean Science
tupper@seadas.bigelow.org
pemaquidriver@tidewater.net
|
|
|