简体   繁体   中英

understanding the arange() function in NumPy

import numpy as np
print(np.arange(-2, 2, 0.5, int))

so we have -2 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5

output: [-2 -1 0 1 2 3 4 5]

can someone explain the output?

Basically, what you have is rounding of float (-1.5) to an integer(-1). Then arrange() continues addition to a new integer(-1+0.5), which results in float(0.5) again. The floats are not allowed, so it's rounded to 0. And so the cycle continues producing observed output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM