Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Access array elements with String
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 11:16 am
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 08:16:28 -0700 (PDT)
Local: Mon, Jul 14 2008 11:16 am
Subject: Access array elements with String
Hello all,

Another issue - perhaps one of you has encountered this before.  It's
sort of a neat problem.  I'm attempting to build array subscripts on
the fly based on user input. IE the number of static/variable elements
is changing, which allows the user to pick different axes to plot.
Nevermind all that.

Anyway, let's say a user wants a particular axis to be variable.  In
this case, the dataset array where I'm attempting to pull values from
would contain a *, to get all these elements.  Unfortunately, I do not
know in advance which dimension of the array I will be using, so I am
attempting to build the subscript based on a string.

This was my original thought:
a = dindgen(5,5,5)
b = ['3','3','3']
print, a[b]
but this just returns a[3], a[3], a[3]

So, I figured I'd do it this way:
c = '3'
print, a[c,c,c] -- This works!

Now for the gold,
d = '*'
print, a[c,c,d] -- error - can't convert string-> long
so I get an idea-- maybe I'll just use the ascii value for the
asterisk.
d = String(42b)
print, a[c,d,d] -- error - can't convert string-> long

Any thoughts ?
Thanks in advance
--Justin


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Crawford  
View profile  
 More options Jul 14 2008, 11:41 am
Newsgroups: comp.lang.idl-pvwave
From: Bob Crawford <Snowma...@gmail.com>
Date: Mon, 14 Jul 2008 08:41:06 -0700 (PDT)
Local: Mon, Jul 14 2008 11:41 am
Subject: Re: Access array elements with String
On Jul 14, 11:16 am, humanumbre...@gmail.com wrote:

Why try to force the '*' - might not SIZE be more useful?
e.g.
s=SIZE(a)
print, a[c,c,s[3]] ; for a[c,c,d]
print, a[c,s[2],s[3]]; for a[c,d,d]

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 11:49 am
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 08:49:24 -0700 (PDT)
Local: Mon, Jul 14 2008 11:49 am
Subject: Re: Access array elements with String
On Jul 14, 11:41 am, Bob Crawford <Snowma...@gmail.com> wrote:

Hey Bob,

Thanks for the post!
I think I may need to elaborate a bit more --
I need the entire row of the multi-dimensional array.
So, for example, let's say I have an array that is 30 x 20 x 50
I will need *,0,0 to plot the first 30 values
but I could just as easily need 0,*,0 or 0,0,* Depending on user
input, so I can't anticipate that in advance.

Cheers,
--Justin


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Crawford  
View profile  
(1 user)  More options Jul 14 2008, 12:30 pm
Newsgroups: comp.lang.idl-pvwave
From: Bob Crawford <Snowma...@gmail.com>
Date: Mon, 14 Jul 2008 09:30:03 -0700 (PDT)
Local: Mon, Jul 14 2008 12:30 pm
Subject: Re: Access array elements with String
On Jul 14, 11:49 am, humanumbre...@gmail.com wrote:

Oops.
I posted too soon (thank you for the clarification Justin - that is
what I was trying to do)
Here is what I should have posted:

print, a[c,c,0:(s[3]-1)] ; for a[c,c,d]
print, a[c,0:(s[2]-1),0:(s[3]-1)]; for a[c,d,d]

Isn't '*' just short form notation for 0:(s[n]-1), anyway?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 12:59 pm
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 09:59:26 -0700 (PDT)
Local: Mon, Jul 14 2008 12:59 pm
Subject: Re: Access array elements with String
On Jul 14, 12:30 pm, Bob Crawford <Snowma...@gmail.com> wrote:

Hey Bob,

Yes, I think '*' is short for 0:(s[n]-1) but I read somewhere that you
shouldn't use the range because of performance issues...
Can anyone shed light on that issue?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 1:06 pm
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 10:06:33 -0700 (PDT)
Local: Mon, Jul 14 2008 1:06 pm
Subject: Re: Access array elements with String
On Jul 14, 12:59 pm, humanumbre...@gmail.com wrote:

IE:
From the "Help" pages on "Arrays"
"Processing subscript ranges is inefficient. When possible, use an
array or scalar subscript instead of specifying a subscript range
where the beginning and ending subscripts are separated by the colon
character."

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Fanning  
View profile  
 More options Jul 14 2008, 1:09 pm
Newsgroups: comp.lang.idl-pvwave
From: David Fanning <n...@dfanning.com>
Date: Mon, 14 Jul 2008 11:09:41 -0600
Local: Mon, Jul 14 2008 1:09 pm
Subject: Re: Access array elements with String

humanumbre...@gmail.com writes:
> "Processing subscript ranges is inefficient. When possible, use an
> array or scalar subscript instead of specifying a subscript range
> where the beginning and ending subscripts are separated by the colon
> character."

I think article might shed some light:

   http://www.dfanning.com/misc_tips/submemory.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 3:01 pm
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 12:01:18 -0700 (PDT)
Local: Mon, Jul 14 2008 3:01 pm
Subject: Re: Access array elements with String
On Jul 14, 1:09 pm, David Fanning <n...@dfanning.com> wrote:

It looks like the asterisk character is interpreted as something
different inside the brackets of an array.
This interpretation is not a string '*', so that would explain the
error of trying to use the string in this context.

Is anyone familiar with how to reformat the * in such a way so as the
interpreter would recognize it ?

Thanks in advance,
--Justin


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Crawford  
View profile  
 More options Jul 14 2008, 3:23 pm
Newsgroups: comp.lang.idl-pvwave
From: Bob Crawford <Snowma...@gmail.com>
Date: Mon, 14 Jul 2008 12:23:40 -0700 (PDT)
Local: Mon, Jul 14 2008 3:23 pm
Subject: Re: Access array elements with String
On Jul 14, 1:06 pm, humanumbre...@gmail.com wrote:

It appears from my reading of David's page that quoting the subscripts
by way of using a colon is not any different (memory wise) than using
a '*'.

Given the passage you've quoted above doesn't state that using a '*'
is any more efficient than ':' subsetting, but perhaps doing (as
suggested):

b=INDGEN(s(3))
print, a[c,c,b]

might be more efficient - dunno, haven't tested.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul van Delst  
View profile  
(1 user)  More options Jul 14 2008, 3:46 pm
Newsgroups: comp.lang.idl-pvwave
From: Paul van Delst <Paul.vanDe...@noaa.gov>
Date: Mon, 14 Jul 2008 15:46:34 -0400
Local: Mon, Jul 14 2008 3:46 pm
Subject: Re: Access array elements with String

What about using execute? I didn't have any problems constructing a string to execute that
included the '*' character:

pro testit, n
   a=indgen(30,20,50)
   help, a
   info=size(a,/structure)

   index = make_array(info.n_dimensions,value='0')
   index[n] = '*'

   exestring = 'x = reform(a['+strjoin(index,',')+'])'
   result = execute(exestring)
   help, x
end

IDL> testit,0
A               INT       = Array[30, 20, 50]
X               INT       = Array[30]
IDL> testit,1
A               INT       = Array[30, 20, 50]
X               INT       = Array[20]
IDL> testit,2
A               INT       = Array[30, 20, 50]
X               INT       = Array[50]

??

cheers,

paulv


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 3:58 pm
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 12:58:45 -0700 (PDT)
Local: Mon, Jul 14 2008 3:58 pm
Subject: Re: Access array elements with String
On Jul 14, 3:46 pm, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:

Paulv,

You're the champion of the day!  Thanks kindly for your suggestion!

I was unaware of the execute command.

Thanks !!
Cheers,
--Justin


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jean H  
View profile  
(1 user)  More options Jul 14 2008, 3:49 pm
Newsgroups: comp.lang.idl-pvwave
From: Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
Date: Mon, 14 Jul 2008 13:49:05 -0600
Local: Mon, Jul 14 2008 3:49 pm
Subject: Re: Access array elements with String

> It looks like the asterisk character is interpreted as something
> different inside the brackets of an array.
> This interpretation is not a string '*', so that would explain the
> error of trying to use the string in this context.

> Is anyone familiar with how to reformat the * in such a way so as the
> interpreter would recognize it ?

> Thanks in advance,
> --Justin

well... Bob gave you two solutions already      
0:s[n] and
indgen(s[n])

Now if you really want to use the *, you might want to have a look at
the command "execute"
IDL> a = '*'
IDL> b = indgen(3,3)
IDL> c = '1'
IDL> tmp= execute('e = b[' + c + ',' + a +']')
IDL> print,e
        1
        4
        7

but be aware of the limitations of this command (read the help)
Jean


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jean H  
View profile  
 More options Jul 14 2008, 3:44 pm
Newsgroups: comp.lang.idl-pvwave
From: Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
Date: Mon, 14 Jul 2008 13:44:18 -0600
Local: Mon, Jul 14 2008 3:44 pm
Subject: Re: Access array elements with String

> b=INDGEN(s(3))
> print, a[c,c,b]

> might be more efficient - dunno, haven't tested.

You would have to reformat (i.e. repeat the value) c so it has the same
size as b.

Jean


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
humanumbre...@gmail.com  
View profile  
 More options Jul 14 2008, 4:17 pm
Newsgroups: comp.lang.idl-pvwave
From: humanumbre...@gmail.com
Date: Mon, 14 Jul 2008 13:17:02 -0700 (PDT)
Local: Mon, Jul 14 2008 4:17 pm
Subject: Re: Access array elements with String
On Jul 14, 3:44 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:

> > b=INDGEN(s(3))
> > print, a[c,c,b]

> > might be more efficient - dunno, haven't tested.

> You would have to reformat (i.e. repeat the value) c so it has the same
> size as b.

> Jean

Thanks Bob,

In my particular application, it was difficult to use the solution
involving the range, because I had to put ':' in the dataset access
function.  I do not know how many dimensions are in advance, so I
would need to switch on the number of dimensions in order to put the
right number of ':' in.  I could be missing something,

Thanks Jean for the caution on the execute command, and I will check
out the help menu.

Thanks again everyone.
Cheers.
--Justin


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google