Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Position of Sign change in long list

  • To: mathgroup at
  • Subject: [mg18706] Re: [mg18691] Position of Sign change in long list
  • From: Jean-Marie Thomas <jmt at>
  • Date: Sat, 17 Jul 1999 02:36:31 -0400
  • Organization: TeA
  • References: <>
  • Sender: owner-wri-mathgroup at

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,


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

  • Prev by Date: Re: Rudimentary Spell Checker
  • Next by Date: Re: data acquisition system with mathematica 3.0
  • Previous by thread: Position of Sign change in long list
  • Next by thread: Re: Position of Sign change in long list