Re: Position of Sign change in long list
- To: mathgroup at smc.vnet.net
- Subject: [mg18706] Re: [mg18691] Position of Sign change in long list
- From: Jean-Marie Thomas <jmt at agat.net>
- Date: Sat, 17 Jul 1999 02:36:31 -0400
- Organization: TeA
- References: <199907150546.BAA15968@smc.vnet.net.>
- Sender: owner-wri-mathgroup at wolfram.com
Try this : Timing at Catch@Module[{i,s=0}, s=Sign at First@test; Scan[(++i,If[Sign at #!=s,Throw at i])&,test]] Hope this helps, jmt On Thu, 15 Jul 1999, Martin Rommel wrote: > I have a long list of data points and need to find the position where the > sign changes for the first time. > My first attempt was > > test=Table[Sin[Pi i/5000. +1],{i,10000}]; > > With[{a=Abs[test]},Position[a,Min[a]]] > > which works, but is slow. It turns out that Min is relatively slow and > avoiding it can save time. The following is almost a factor 4 faster: > > With[{st=Sign[test]},Length[Split[st][[1]]]] > > If you can think of a still faster or more elegant solution please let me > know! > > Martin
- References:
- Position of Sign change in long list
- From: "Martin Rommel" <rommel@semitest.com>
- Position of Sign change in long list