jaxvacua.util.flatten_top#
- flatten_top(arr, as_list=True, N=1)#
Flatten the top
Nlevels (axis 0) of a nested iterable.- Parameters:
arr (
Iterable) – The input (can be ragged).as_list (
bool) – IfTrue(default), return a list; otherwise return anp.ndarray.N (
int) – Number of top levels to flatten. Default1.
- Returns:
list | np.ndarray –
arrwith its topNlevels flattened.- Return type:
Union[list,ndarray]
Example
A = np.asarray(range(2**3)).reshape(2, 2, 2) flatten_top(A.tolist()) # [[0, 1], [2, 3], [4, 5], [6, 7]] flatten_top(A.tolist(), N=2) # [0, 1, 2, 3, 4, 5, 6, 7]