【发布时间】:2018-12-15 22:18:36
【问题描述】:
我无法理解为什么我的 jupyter 笔记本每次执行时都会显示 TypeError 的浮点数。
A = np.random.rand(1e4, 1e4).astype('float32')
B = np.random.rand(1e4, 1e4).astype('float32')
c1 = []
c2 = []
def matpow(M, n):
if n < 1: #Abstract cases where n < 1
return M
else:
return tf.matmul(M, matpow(M, n-1))
错误:
Traceback (most recent call last)
<ipython-input-5-61ea4b300d55> in <module>()
1 # Example: compute A^n + B^n on 2 GPUs
2 #Create random Large matrix
----> 3 A = np.random.rand(1e4, 1e4).astype('float32')
4 B = np.random.rand(1e4, 1e4).astype('float32')
5
mtrand.pyx in mtrand.RandomState.rand()
mtrand.pyx in mtrand.RandomState.random_sample()
mtrand.pyx in mtrand.cont0_array()
TypeError: 'float' object cannot be interpreted as an index
【问题讨论】:
-
请正确格式化您的问题
-
一旦你意识到 OP 意味着整数而不是索引,这是一个重复。 stackoverflow.com/questions/32687012/…
-
您错误地陈述了您的问题。它不应该说'float'对象不能被解释为整数吗?不是索引。标题相同。
标签: python tensorflow typeerror