通过随机指数的张量数组选择或切片张量?

2024-04-25 23:06:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在TensorFlow中复制这个:

mat = np.matrix("1,2,3;4,5,6;7,8,9")
matrix([[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]])
mat[2]
matrix([[7, 8, 9]])

我得到这个错误:

X_batch = X_train[batch]

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

X_trainbatch_size x (other dimensions)batch是随机值的一维张量。在

我试着从一个训练集中随机抽取一批(实际上我想弄清楚如何训练多个时期,question here),并认为索引的随机张量是一种方法,但这不起作用。在


Tags: integersnumpynoneonlytensorflow错误npbatch