Why combine np.floor function and the // operator in Python?
题
I am reading the source code of the library 'scikits-image' written in Python, I found the next line of code:
n_cellsx = int(np.floor(sx // cx))
I don't know why they join the NumPy function floor
and the //
operator. Is there any reason to do this? I can't see. I feel that is doing the same thing twice.
The project is here
解决方案
There is no reason to do that, //
will return either an integer or a float corresponding to an integer, so floor
will do nothing.
其他提示
As for the why do the whole thing: They might want to cut a given number of following zeros... Check out this example:
>>> int(np.floor(40 // 10))
Out[40]: 4
if one just did int, then he would get 40....
As for why the int part,
>>> (49 // 10.0)
Out[50]: 4.0
The floor() part does nothing however, unless the code used to have / instead of //, or the programmer is afraid a colleague might substitute // with / ...