Stupid Question?

Markus Stenberg mstenber at cc.Helsinki.FI
Fri Aug 6 04:21:53 CEST 1999

"jim moore" <indiana at> writes:
> Is there a bulit in function that will give you N evenly spaced numbers
> between X1 and X2.  For example: 10 numbers between 0 and 1 ([0.1, 0.2, 0.3,
> ...])

Uh, sounds pretty trivial to me: 

def linspace(v1,v2,n):
	return map(lambda x,v1=v1,v2=v2,n=n:\
		   v1+float(v2-v1)*(1+x)/(n+1), range(n))

I don't see why everything should be builtin :P

> It would be similar to MATLAB's linspace.
> How about a function similar to range but allowing a floating point step?
> Seems like there would be one out there, so I thought I'd check before I
> wrote one.

Same thing; range's quick-and-dirty integer thingy, if there was float
checks or stuff for the step, it'd slow down slightly or great deal, and I
don't see much of a gain in it. 

> Thanks,
> Jim Moore


"Chicks will dig you if you use Debian!  Running RedHat is
like going to the beach to scope out the action while wearing
your water wings."
        -- slashdot comment

More information about the Python-list mailing list