MathGroup Archive 2003

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

Search the Archive

Re: Nonzero Min[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43508] Re: [mg43447] Nonzero Min[]
  • From: Michael Schreiber <michaelschreiber at mac.com>
  • Date: Thu, 18 Sep 2003 05:40:03 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In[1199]:=
dat2=Join[dat,{0,0.}];

In[1206]:=
Timing[Min[DeleteCases[DeleteCases[dat2,0.],0]]]

Out[1206]=
{0.07 Second,0.00108951}

On Wednesday, Sep 17, 2003, at 13:59 Europe/Vienna, Petr Kujan wrote:

> Hello MathGroup,
>    I need function which finds nonzero minimum in the list. My
> definitions are now slower in comparison with kernel function Min[ ].
>
>
> findmin1[data_] := Min[data]
> findmin1[dat] // Timing  (* 0.01 Second*) (* Very good time consumption
> but wrong result for me. *)
>
>
> It's possible shorter time consumption for this problem?
>
> (*************************************************************)
> My definition are now:
>
> (* Testing data are Integer or Real numbers (possible mixed). *)
> SeedRandom[1];
> dat = Abs[Join[Array[Random[
>       Integer, {-10, 10}]&, {10^4}], Array[Random[Real, {-10, 10}]&,
> {10^4}]]];
>
> (*** 2. - Select ***)
> findmin2[data_] := Min[Select[data, Not[ZeroQ[#]]&]];
> findmin3[dat] // Timing
> (* 0.12 Second *)
>
> (*** 3. - Sort ***)
> dropfirstzeros[dat_List] := Block[{i}, i = 1;
>         While[ZeroQ[dat[[i]]], i = i + 1;];
>         Drop[dat, i - 1]];
> findmin2[data_] := dropfirstzeros[Sort[data]][[1]];
> findmin2[dat] // Timing
> (* 0.14 Second *)
>
> (*** 4. - Map ***)
> getnznum[list_] := Block[{i = 1},
>         While[ZeroQ[list[[i]]], i++]; list[[i]]
>         ];
> findmin4[data_] := Block[{minim = getnznum[data]},
>         If[(# > 0) && (minim > #), minim = #] & /@ data;
>         minim
>         ];
> findmin4[dat] // Timing
> (* 0.26 Second *)
>
> (*** 5. - Do ***)
> getnznum[list_] := Block[{i = 1},
>             While[ZeroQ[list[[i]]], i++]; list[[i]]
>         ];
> findmin5[data_] := Block[{minim, p},
>       minim = getnznum[data];
>       Do[
>         p = data[[i]];
>         If[((p > 0) && (minim > p)), minim = p],
>         {i, 1, Length[data]}
>         ];
>       minim
>       ]
> findmin5[dat] // Timing
> (* 0.32 Second *)
> (*************************************************************)
>
> Thank in advance for all your help.
> Best regards,
>     Petr.
>
>
M F Schreiber
Heimscholleg 26 Wien, A1130 Austria Europe
Michael at Schreiber.at


  • Prev by Date: Re: Nonzero Min[]
  • Next by Date: Re: 14MB image very quickly exhausts 512MB RAM.
  • Previous by thread: Re: Nonzero Min[]
  • Next by thread: Re: Nonzero Min[]