python (scipy) TypeError
MRAB
python at mrabarnett.plus.com
Mon Oct 3 13:54:34 EDT 2016
On 2016-10-03 17:48, chrischris201444 at gmail.com wrote:
> Τη Δευτέρα, 3 Οκτωβρίου 2016 - 7:17:03 μ.μ. UTC+3, ο χρήστης chrischr... at gmail.com έγραψε:
>> hello
>>
>>
>> i try to follow some tutorial but i have that error :
>>
>> Traceback (most recent call last):
>> File "C:\Python27\test\test\earth.py", line 42, in <module>
>> slope_array = np.ones_like(data_array) * nodataval
>> TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
>>
[snip]
>>
>> #Show the visualization
>> plt.axis('off')
>> plt.title("Slope (degrees)")
>> plt.show()
>> plt.close()
> yes you are correct i solution this error but now i have another error in the line :color_bounds = list(range(-3, math.ceil(np.amax(slope_array)), 1))
>
> error massage :
> Traceback (most recent call last):
> File "C:\Python27\test\test\earth.py", line 95, in <module>
> color_bounds = list(range(-3, math.ceil(np.amax(slope_array)), 1))
> TypeError: range() integer end argument expected, got float.
>
>
> any idea ?
>
Look at the help for math.ceil:
>>> help(math.ceil)
Help on built-in function ceil in module math:
"""
ceil(...)
ceil(x)
Return the ceiling of x as a float.
This is the smallest integral value >= x.
"""
It returns an integer value, but as a _float_.
'range' expects an int, not a float, so you'll need to convert the float
to an int:
color_bounds = list(range(-3, int(math.ceil(np.amax(slope_array))), 1))
Did you copy the code straight from the tutorial?
You're using Python 2.7, but for which version of Python was the
tutorial written? Python 2 or Python 3?
If it was written for Python 3 and you're using Python 2, that might
explain why the code isn't working for you. (In Python 2, math.ceil
returns a float, whereas in Python 3 it returns an int.)
More information about the Python-list
mailing list