I have a NumPy ndarray A of size (k,n,m) of int, representing k images each of size nxm pixels. I would like to convert it into a dtype=object ndarray B of size (k,) containing each of the individual images as ndarrays of size (n,m).
I can do it with a for-loop (below), but is there a more elegant/straightforward way?
A = np.arange(2*3*4).reshape(2,3,4)
B = np.empty(A.shape[0],dtype=object)
for i in range(0,A.shape[0]):
B[i] = A[i]
print(B)
array([array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]), array([[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]])], dtype=object)