Numpy: creating batch of numpy arrays within another numpy array (reshaping) Numpy: creating batch of numpy arrays within another numpy array (reshaping) numpy numpy

Numpy: creating batch of numpy arrays within another numpy array (reshaping)


Assuming I understand the problem correctly, you can stack twice on the last axis.

res = np.stack(np.stack(batch[:,0])[...,0])


import numpy as np# fabricate some databatch = np.array((32, 1), dtype=object)for i in range(len(batch)):    batch[i] = [np.random.rand(84, 84, 3), None, None]# select imagesresult = np.array([img for img, _, _ in batch])# double check!for i in range(len(batch)):    assert np.all(result[i, :, :, :] == batch[i][0])