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

Home » Public Forums » archive » Re: findgen([variable])
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: findgen([variable]) [message #22890] Tue, 12 December 2000 11:50
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Not only was my suggestion "Oof", but it was downright wrong, too, I am
afraid :-( Perfect mental state to get ready for that conference, Pavel.
But, if I didn't post this ugly one, how else would this thread stir up
so much nice input from the better ones? You guys were dormant there for
a couple of hours!

Cheers,
Pavel

Paul van Delst wrote:

> Oof!
> ...... snip
> paulv
Re: findgen([variable]) [message #22891 is a reply to message #22890] Tue, 12 December 2000 11:33 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
Craig Markwardt wrote:
>
> JD Smith <jdsmith@astro.cornell.edu> writes:
>
>> Craig Markwardt wrote:
>>>
>>> Martin Skou Andersen <skou@fys.ku.dk> writes:
>>>> Is it posible to make an mutiple dimensional array by using a variable
>>>> such as findgen(x)?
>>>
>>> This is virtually impossible, right? You are asking for each row of
>>> the resulting array to be of a different length. That's not really a
>>> 2 dimensional array is it?
>>
>>
>> Are we sure he doesn't just mean:
>>
>> findgen(x[0],x[1]) ?
>
> Ah yes, that would be a good idea. In fact, one of my "top ten"
> requests was to have all of the functions that accept dimensions,
> accept them in a consistent way. REBIN, REFORM and TOTAL are all
> different. We should be able to specify dimensions consistently
> between them, and either as an array, or a list of scalars.

Or as either, as in Perl, where

@a=($a1,$a2);
sub(@a);

sub($a1,$a2)

are the same. A list is a list is a list. This simplifies a lot of
things (and of course requires atomic list members (i.e. pointers),
since you can't have separate lists and scalars all on the command
line).

Not that we could ever get away with that kind of facelift, but PerlDL
of course has hope.

JD
Re: findgen([variable]) [message #22892 is a reply to message #22891] Tue, 12 December 2000 11:24 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Craig Markwardt wrote:
>
> Paul van Delst <pvandelst@ncep.noaa.gov> writes:
>> Oof!
>
> Looks like we posted at the same time. Oof indeed. :-)
>
>> Why doesn't MAKE_ARRAY allow for a dimension vector input?
>
> It does, ever try the DIMENSION keyword, sonny? :-)

Oh yeah.... I still haven't received your post on my server (you're at GSFC, right, so that's
probably why...last on the list of NOAA server updates :o) so this is probably the same as you put
together:

IDL> x=[5,7]
IDL> help, make_array(dimension=x,/index)
<Expression> FLOAT = Array[5, 7]
IDL> print, make_array(dimension=x,/index)
0.00000 1.00000 2.00000 3.00000 4.00000
5.00000 6.00000 7.00000 8.00000 9.00000
10.0000 11.0000 12.0000 13.0000 14.0000
15.0000 16.0000 17.0000 18.0000 19.0000
20.0000 21.0000 22.0000 23.0000 24.0000
25.0000 26.0000 27.0000 28.0000 29.0000
30.0000 31.0000 32.0000 33.0000 34.0000

Veddy nice

No need for any "PRODUCT"-ing

cool

paulv

--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.207, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
Re: findgen([variable]) [message #22893 is a reply to message #22892] Tue, 12 December 2000 11:07 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Paul van Delst <pvandelst@ncep.noaa.gov> writes:
> Oof!

Looks like we posted at the same time. Oof indeed. :-)

> Seems that determining "n" is the hard part...is there a "PRODUCT" type of function in IDL? Like
> TOTAL but with * rather than + as the operator.

There is PRODUCT in the IDL Astronomy Library, and CMPRODUCT from my
web page, which I purport to be faster in most cases. Alas, there is
no built-in IDL support, but there should be. Make that my "top
eleventh" request.

> Why doesn't MAKE_ARRAY allow for a dimension vector input?

It does, ever try the DIMENSION keyword, sonny? :-)

Craig

http://cow.physics.wisc.edu/~craigm/idl/idl.html

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: findgen([variable]) [message #22894 is a reply to message #22893] Tue, 12 December 2000 10:52 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
JD Smith <jdsmith@astro.cornell.edu> writes:

> Craig Markwardt wrote:
>>
>> Martin Skou Andersen <skou@fys.ku.dk> writes:
>>> Is it posible to make an mutiple dimensional array by using a variable
>>> such as findgen(x)?
>>
>> This is virtually impossible, right? You are asking for each row of
>> the resulting array to be of a different length. That's not really a
>> 2 dimensional array is it?
>
>
> Are we sure he doesn't just mean:
>
> findgen(x[0],x[1]) ?

Ah yes, that would be a good idea. In fact, one of my "top ten"
requests was to have all of the functions that accept dimensions,
accept them in a consistent way. REBIN, REFORM and TOTAL are all
different. We should be able to specify dimensions consistently
between them, and either as an array, or a list of scalars.

Here is my entry. Sorry, no HISTOGRAM call, but I need to give it a
rest once in a while.

nel = dims(0)
for i = 1L, n_elements(dims)-1 do nel = nel * dims(i)
arr = reform(findgen(nel), dims)

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: findgen([variable]) [message #22895 is a reply to message #22894] Tue, 12 December 2000 10:33 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
"Pavel A. Romashkin" wrote:
>
> I am afraid FINDGEN can not take a vector for dimensions. What I would
> try is either using a vector
>
> x = [5, 7]
> r = findgen(total(x))
>
> which still would allow transparent indexing of R. If I really needed
> multi D arrays, I'd use EXECUTE and build a command string using
> dimensions of X:
>
> x = [5, 7]
> com = 'r = findgen('
> for i =0, n_elements(x)-1 do com = com +'x['+string(i)+']'+ $
> string(44b*byte(i ne n_elements(x)-1) > 41b)
> i=execute(com)
>
> EXECUTE is not cute, but I can't come up with anything nicer. I need
> another cup of coffe :-(

Oof!

What about

IDL> x=[5,7]
IDL> ndim=n_elements(x)
IDL> n=1L
IDL> for i=0,ndim-1 do n=n*x[i]
IDL> help, reform(findgen(n),x)
<Expression> FLOAT = Array[5, 7]
IDL> print, reform(findgen(n),x)
0.00000 1.00000 2.00000 3.00000 4.00000
5.00000 6.00000 7.00000 8.00000 9.00000
10.0000 11.0000 12.0000 13.0000 14.0000
15.0000 16.0000 17.0000 18.0000 19.0000
20.0000 21.0000 22.0000 23.0000 24.0000
25.0000 26.0000 27.0000 28.0000 29.0000
30.0000 31.0000 32.0000 33.0000 34.0000

Seems that determining "n" is the hard part...is there a "PRODUCT" type of function in IDL? Like
TOTAL but with * rather than + as the operator.

Why doesn't MAKE_ARRAY allow for a dimension vector input?

paulv

--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.207, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
Re: findgen([variable]) [message #22896 is a reply to message #22895] Tue, 12 December 2000 10:20 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
Craig Markwardt wrote:
>
> Martin Skou Andersen <skou@fys.ku.dk> writes:
>> Is it posible to make an mutiple dimensional array by using a variable
>> such as findgen(x)?
>
> This is virtually impossible, right? You are asking for each row of
> the resulting array to be of a different length. That's not really a
> 2 dimensional array is it?


Are we sure he doesn't just mean:

findgen(x[0],x[1]) ?

JD
Re: findgen([variable]) [message #22899 is a reply to message #22896] Tue, 12 December 2000 09:53 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Oh Craig, I expected an answer involving HISTOGRAM from you :-(

Cheers,
Pavel

Craig Markwardt wrote:
>
> Martin Skou Andersen <skou@fys.ku.dk> writes:
>> Is it posible to make an mutiple dimensional array by using a variable
>> such as findgen(x)?
>
> This is virtually impossible, right? You are asking for each row of
> the resulting array to be of a different length. That's not really a
> 2 dimensional array is it?
>
> Craig
Re: findgen([variable]) [message #22900 is a reply to message #22899] Tue, 12 December 2000 09:45 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
I am afraid FINDGEN can not take a vector for dimensions. What I would
try is either using a vector

x = [5, 7]
r = findgen(total(x))

which still would allow transparent indexing of R. If I really needed
multi D arrays, I'd use EXECUTE and build a command string using
dimensions of X:

x = [5, 7]
com = 'r = findgen('
for i =0, n_elements(x)-1 do com = com +'x['+string(i)+']'+ $
string(44b*byte(i ne n_elements(x)-1) > 41b)
i=execute(com)

EXECUTE is not cute, but I can't come up with anything nicer. I need
another cup of coffe :-(

Cheers,
Pavel

Martin Skou Andersen wrote:
>
> Hi...
> I was wondering if I could use findgen with a variable.
> If I in one situation would use a one dimension array and in another
> situation a mutiple dimension array how would i do?
> I have tried with findgen(x), where x could be an integer or an array.
> But when x is an array IDL gives me following error message:
> IDL> r=fltarr(x)+10
> % FLTARR: Expression must be a scalar in this context: X.
> % Execution halted at: $MAIN$
>
> where x is:
> IDL> print,x
> 5 7
> IDL> help,x
> X INT = Array[2]
> Is it posible to make an mutiple dimensional array by using a variable
> such as findgen(x)?
> --
> Thanx in advance
> Martin Skou Andersen
> E-mail: Skou@fys.ku.dk
> Martin_Skou@mail.tele.dk
> Homepage: http://www.fys.ku.dk/~skou/
Re: findgen([variable]) [message #22901 is a reply to message #22900] Tue, 12 December 2000 09:28 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Martin Skou Andersen <skou@fys.ku.dk> writes:
> Is it posible to make an mutiple dimensional array by using a variable
> such as findgen(x)?

This is virtually impossible, right? You are asking for each row of
the resulting array to be of a different length. That's not really a
2 dimensional array is it?

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL and external app in concurrent mode
Next Topic: Background colors in PNG files?

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

Current Time: Thu Oct 09 07:53:55 PDT 2025

Total time taken to generate the page: 0.71871 seconds