MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: converting a list element into a number?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98610] Re: converting a list element into a number?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 14 Apr 2009 06:16:48 -0400 (EDT)

On 4/13/09 at 3:35 AM, meitnik at gmail.com (meitnik) wrote:

>Hi I have noticed when using Position[], it returns a single element
>list. So how do I convert that into a number other than using
>Flatten to strip off the braces? It seems if I use Flatten within
>any subroutine code, I get the error code thats its "Protected". So
>how do I work around using Flatten??

Here is an example to get a number

In[2]:= Position[Range[5], 3][[1, 1]]

Out[2]= 3

to get a 1-D list

In[3]:= Position[Range[5], 3][[1]]

Out[3]= {3}

or

In[4]:= First@Position[Range[5], 3]

Out[4]= {3}

Note, there is no problem using Flatten in a subroutine. Getting
the error you described says there is something wrong with your
code. Possibly, you are making an assignment to Flatten which
would generate this error.




  • Prev by Date: Re: Bug fixing reporting and fixing rate of Mathematica
  • Next by Date: Re: Best practices of coding using Mathematica?
  • Previous by thread: converting a list element into a number?
  • Next by thread: Re: converting a list element into a number?