Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5472
| From | Adriano Pascoletti <adriano.pascoletti@uniud.it> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: list equation |
| Date | 2011-10-07 08:50 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j6mege$7at$1@smc.vnet.net> (permalink) |
| References | <201110060824.EAA22708@smc.vnet.net> |
In[1]:= lst = Tuples[Range[100], 2];
In[9]:= Timing[lstnew = Union[lst, SameTest -> (#1 == Reverse[#2] & )]; ]
Out[9]= {39.09032700000002, Null}
Faster
In[10]:= Timing[lstnew1 = DeleteDuplicates[Sort /@ lst]; ]
Out[10]= {0.008493999999998891, Null}
In[11]:= lstnew === lstnew1
Out[11]= True
Much faster
In[12]:= Timing[lstnew1 = (Sequence @@ Thread[{#1, Range[#1, 100]}] & ) /@
Range[100]; ]
Out[12]= {0.003968000000000416, Null}
In[13]:= lstnew1 === lstnew
Out[13]= True
Adriano Pascoletti
2011/10/6 dimitris <dimmechan@yahoo.com>
> Hello to all.
>
> Let
>
> lst = Tuples[Range[100], 2];
>
> In the previous list appear elements such us {x,y} and {y,x}. (e.g.
> {3,4} and {4,3}).
> I want to create a new list with {y,x} dropped (that is, in the new
> list appears only {3,4}
> and not {4,3}).
>
> I use
>
> lstnew = Union[lst, SameTest -> (#1 == Reverse[#2] &)]
>
> However it is needed almost 150 sec for this procedure ($Version->5.2
> for Windows)
> I know that my laptop is too old but I guess there is a more efficient
> way to
> create lstnew.
>
> Any ideas?
>
> Thanks a lot
>
> Dimitris
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: list equation Adriano Pascoletti <adriano.pascoletti@uniud.it> - 2011-10-07 08:50 +0000
csiph-web