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

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

 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):

你可能感兴趣的:(python)