Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Map to nested list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98263] Re: Map to nested list
  • From: Hartmut.Wolf at t-systems.com
  • Date: Sun, 5 Apr 2009 06:31:08 -0400 (EDT)
  • References: <200904030933.EAA11449@smc.vnet.net>

>-----Original Message-----
>From: athanase [mailto:aeoost at gmail.com]
>Sent: Friday, April 03, 2009 11:34 AM
>To: mathgroup at smc.vnet.net
>Subject:  Map to nested list
>
>this expression
>
>IntegerQ/@{1,1/5}
>
>outputs {True, False}
>
>which operator is used for nested list?
>
>so
>
>IntegerQ ? {{1,1/5},{1,1/5}}
>
>outputs {{True, False},{True, False}}
>
>
>thankyou :)
>
>

Well usually it's Map, it depends a bit on your "nesting", e.g.:

In[3]:= Map[IntegerQ, {{1, 1/5}, {1, 1/5}}, {2}]
Out[3]= {{True, False}, {True, False}}


If nesting is different, map differently, e.g.:

In[16]:= Map[IntegerQ, {1, {2., {3, {4., 5}}}}, {-1}]
Out[16]= {True, {False, {True, {False, True}}}}


This might wreak havoc however, with

In[14]:= Map[IntegerQ, {{1, 1/5}, {{1, 1/5}, 1/f[5]}}, {-1}]
Out[14]= {{True, False}, {{True, False}, Power[f[True],True]}}


If you only want to map within Lists descending, you might try

In[19]:= th[IntegerQ,{{1, 1/5},{{1,1/5},1/f[5]}}]
Out[19]= {{True,False},{{True,False},False}}

In[17]:= th[IntegerQ, {1, {2., {3, {4., 5}}}}]
Out[17]= {True, {False, {True, {False, True}}}}


Where th maps recursively at List:

In[11]:= th[f_, a_] /; Head[a] == List := th[f, #] & /@ a
In[12]:= th[f_, a_] := f[a]


--
Hartmut


  • Prev by Date: Re: passing an array variable as a file name string to FindList
  • Next by Date: Re: release memory
  • Previous by thread: Re: Map to nested list
  • Next by thread: Map to nested list