if not np.isnan(A[A.shape[0] // 2, 0]):
    return [rect for part in np.split(A, 2, axis=0) for rect in recurse(part)]
elif not np.isnan(A[A.shape[0] // 2, 0]):
    pass
Numpy -- Split 2D array into sub-arrays based on indices