From: Bill B. <wb...@gm...> - 2006-08-21 16:27:23
|
Out of curiosity I checked on what matlab does. It does explicity set the last value to 'stop' to avoid the roundoff issue. In numpy terms, it does something like y = r_[start+r_[0:num-1]*(stop-start)/(num-1.0), stop] But for numpy it's probably more efficient to just do the 'y[-1] = stop' like you say. --bb On 8/22/06, Alan G Isaac <ai...@am...> wrote: > > The definition of linspace is: > def linspace(start, stop, num=50, endpoint=True, retstep=False): > """Return evenly spaced numbers. > > Return 'num' evenly spaced samples from 'start' to 'stop'. If > 'endpoint' is True, the last sample is 'stop'. If 'retstep' is > True then return the step value used. > """ > num = int(num) > if num <= 0: > return array([], float) > if endpoint: > if num == 1: > return array([float(start)]) > step = (stop-start)/float((num-1)) > else: > step = (stop-start)/float(num) > y = _nx.arange(0, num) * step + start > if retstep: > return y, step > else: > return y > > The simplest way to achieve this goal is to add right after > the assignment to y two new lines: > if endpoint: > y[-1] = float(stop) > > Cheers, > Alan Isaac > > PS I'll take this opportunity to state again my opinion that > in the denerate case num=1 that if endpoint=True then > linspace should return stop rather than start. (Otherwise > endpoint is ignored. But I do not expect anyone to agree.) > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |