|
[Date Index]
[Thread Index]
[Author Index]
Re: List Manipulation (2)
Paul.Hanson@colorado.edu wrote:
> If I have a list of n lists, and want to
> get rid of all the even ones how would I go about doing this? That
> is, {{n1},{n2},.....{2n}} converted to {{n1},{n3}...{2n-1}}.
Paul:
Here is another way:
lst = {{a},{b,c},{d},{e,f,g},{h,a},{k,l,{m,n}},{o,p,q}};
lst[[Table[i,{i,1,Length[lst],2}]]]
{{a},{d},{h,a},{o,p,q}}
It's slightly slower than my earlier posting, which used Partition, but
the increased flexibility is valuable.
tst = Table[i, {10000},{i,Random[Integer,100]}];
Partition[tst,1,2,Sequence];//Timing//First
0.166667 Second
tst[[Table[i,{i,1,Length[tst],2}]]];//Timing//First
0.183333 Second
--
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642
Prev by Date:
Re: How do I tranfer graphics file via Mathlink
Next by Date:
Re: Diamond Video card problems?
Prev by thread:
Backups in Mathematica
Next by thread:
compiled functions
|