[PYTHON MATRIX-SIG] arange w/ fixed # of elements?
David Ascher
da@maigret.cog.brown.edu
Tue, 14 May 1996 20:03:04 -0400 (EDT)
What is the recommended way to get an arange of a given # of elements
between a min & and max?
If I do:
step = (max - min) / float(number)
r = arange(min, max, step)
then I am sometimes getting arrays w/ number + 1 elements, due to
the odd case when max and min are exactly (or close enough) divisible
by the stepsize.
So, the following:
from Numeric import *
def test(s):
x = 1.2*pi / s
n = 300
st = x / 300
if len(arange(0,x,st)) == 301: print s
for x in arange(-5,5,.05):
if x != 0:
test(x)
shows that test(-0.8) and test(-1.6) on my machine yield arrays of size
301, while all the others yield arrays of size 300.
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================