Implement a batch iterator for a dataset. Given a 2D NumPy array X and an integer batch_size, yield successive batches of rows from X. If the dataset size is not evenly divisible by the batch size, the last batch should contain the remaining rows.
import numpy as np
def batch_iterator(X, batch_size=64):
n_samples = X.shape[0]
for i in range(0, n_samples, batch_size):
yield X[i:i + batch_size]range with step batch_size to iterate over starting indices.i to i + batch_size. Python slicing naturally handles the last batch if it is smaller than batch_size.