TypeError: 'float' object cannot be interpreted as an integer

在运行网上代码出现以下错误:
 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-3c49f9c410ab> in <module>()
----> 1 plot_d0(D,input_node)
      2 plt.title('Initial Decision Boundary')
      3 #plt.savefig('fig1.png')

<ipython-input-31-66f62448c15c> in plot_d0(D, input_node)
     10     ds=np.zeros((r,1)) # decision surface
     11     # process multiple points in parallel in a minibatch
---> 12     for i in range(r/M):
     13         x=np.reshape(xs[M*i:M*(i+1)],(M,1))
     14         ds[M*i:M*(i+1)]=sess.run(D,{input_node: x})
TypeError: 'float' object cannot be interpreted as an integer
解决方法:

在python2,/只留下了整数部分,去掉了小数,是int型。而在python3里,/的结果是真正意义上的除法,结果是float型。所以便出现了Error Message: ‘float’ object cannot be interpreted as an integer。

In:

for i in range(r / M):

You're creating a float as a result - to fix this use the int division operator:

for i in range(r // M):

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值