python-Error Message: 'float' object cannot be interpreted as an integer

网上有一中出现的情况如下:

    batch = 200for x in range(len(order_nos) / batch + 1): # do something

此代码在python2下运行正常但是在python3下面运行会出现问题;

原因在于两个版本下对float的处理方法不同,python2下在运行/的时候产生的结果会自动忽略小数,直接取整数,而python3中 是会保留小数点的所以产生了错误


其次,对于

y_linear=x+(5.)*np.random.randn(14.)
这个代码片也会报这个错误原因是在python3中randn里的14.的小数点无法被自动忽略转换成整型导致了错误,所以要根据情况更换使用方法。randn()中的参数一定是正整数

猜你喜欢

转载自blog.csdn.net/qwezhaohaihong/article/details/80360889