我正在尝试学习TensorFLow和NumPY,但是,我似乎遇到了NumPY创建字符串而不是int的问题。
以下是发生错误的代码行:
data = int(np.random.randint(1000, size="10000"))
x = tf.constant(data, name="x")
我得到的错误:
Traceback (most recent call last):
File "D:/TesorLearn/Main.py", line 4, in <module>
data = int(np.random.randint(1000, size="10000"))
File "mtrand.pyx", line 995, in mtrand.RandomState.randint
File "mtrand.pyx", line 996, in mtrand.RandomState.randint
File "randint_helpers.pxi", line 202, in mtrand._rand_int32
TypeError: 'str' object cannot be interpreted as an integer**strong text**
有没有一种方法可以将数组生成为INT?
答案 0 :(得分:1)
好吧,经过一段时间的麻烦,我认为NumPY就像这样:
np.random.randint(low,high.size,dataType)
所以解决我问题的代码行是:
data = np.random.randint(0,1000,10000,int)