Re: Map to nested list
- To: mathgroup at smc.vnet.net
- Subject: [mg98263] Re: [mg98218] Map to nested list
- From: Hartmut.Wolf at t-systems.com
- Date: Fri, 3 Apr 2009 20:11:03 -0500 (EST)
- 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: [mg98218] 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
- References:
- Map to nested list
- From: athanase <aeoost@gmail.com>
- Map to nested list