[PYTHON MATRIX-SIG] arange w/ fixed # of elements?
Konrad HINSEN
hinsenk@ere.umontreal.ca
Tue, 14 May 1996 21:07:15 -0400
> 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.
Try:
min+(max-min)*arange(number)/number
There are no problems with roundoff error in this case.
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal | Fax: +1-514-343-7586
C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7 | Francais (phase experimentale)
-------------------------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================