MATLAB to Python?

Peter Otten __peter__ at web.de
Mon Nov 22 04:11:27 EST 2010


MATLABdude wrote:

> On Nov 17, 10:53 am, Arnaud Delobelle <arno... at gmail.com> wrote:
>> I guess that the step is supposed to be h, so you should write:
>> xx = range(-kappa, kappa+1, h)
> 
> This is what I have in the source code:
> ---8<---8<---8<---8<---
> h =  0.105069988414
> xx = range(-kappa, kappa+1, h)
> ---8<---8<---8<---8<---
> 
> This is what Python says: ValueError: range() step argument must not
> be zero
> 
> Can step not be a float value?

Indeed. Older Pythons will warn you and then try to convert the arguments to 
integers

>>> range(1.0)
__main__:1: DeprecationWarning: integer argument expected, got float
[0]

and in 2.7 or 3.x you'll get a type error:

>>> range(1.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: range() integer end argument expected, got float.

Try numpy.arange() instead:

>>> numpy.arange(0, 1, .1)
array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])





More information about the Python-list mailing list