X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")
y = tf.placeholder(tf.int32, shape=(None), name="y")
X,y均为tensorflow中的占位节点,作用是可以在tensorflow运行过程中向tensorflow传递值
def shuffle_batch(X, y, batch_size):
rnd_idx = np.random.permutation(len(X)) #一个随机排列,作用是将批次内的数据顺序打乱(洗牌)
n_batches = len(X) // batch_size #批次大小
for batch_idx in np.array_split(rnd_idx, n_batches): #将数组拆分为多个子数组。用批次大小来拆分rnd_idx,达到将输入数据分批的目的
X_batch, y_batch = X[batch_idx], y[batch_idx]
yield X_batch, y_batch
>> np.random.permutation(10) array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])>
对于长度为P的数组,应该被分成n个部分,它返回 P%n个子数组,子数组大小为P//(n+1)和P//n。
引用自:https://blog.csdn.net/lw_waston/article/details/83150304
1 在 Python 2.2 :
要引用: from __future__ import division
" / "就表示 浮点数除法,返回浮点结果;" // "表示整数除法。
2 Python 3以后 :
" / "就表示 浮点数除法,返回浮点结果;" // "表示整数除法。