You can also use itertools.filterfalse:
Ave # [array([nan]), array([0.03030303]), array([0.025]), array([0.03546099]), array([0.02877698]), array([0.05343511]), array([nan]), array([nan])] list(itertools.filterfalse(np.isnan, Ave)) # [array([0.03030303]), array([0.025]), array([0.03546099]), array([0.02877698]), array([0.05343511])]
Or if Ave is nested deeper:
AveAveAve = np.random.randint(0, 3, (5, 5, 1)) AveAveAve = np.random.random((5, 5, 1)) * AveAveAve / AveAveAve AveAveAve = list(map(list, AveAveAve)) AveAveAve # [[array([0.25051587]), array([nan]), array([0.93294353]), array([0.45979654]), array([0.46274847])], # [array([nan]), array([0.36631801]), array([0.18432189]), array([0.10408241]), array([nan])], # [array([0.73367427]), array([0.93523268]), array([0.33142847]), array([nan]), array([0.84569255])], # [array([0.95316363]), array([0.67298091]), array([0.06368582]), array([0.22668049]), array([0.14361035])], # [array([0.66480064]), array([0.91260134]), array([0.10735208]), array([0.55708037]), array([0.6402967])]] list(map(list, map(itertools.filterfalse, itertools.repeat(np.isnan), AveAveAve))) # [[array([0.25051587]), array([0.93294353]), array([0.45979654]), array([0.46274847])], # [array([0.36631801]), array([0.18432189]), array([0.10408241])], # [array([0.73367427]), array([0.93523268]), array([0.33142847]), array([0.84569255])], # [array([0.95316363]), array([0.67298091]), array([0.06368582]), array([0.22668049]), array([0.14361035])], # [array([0.66480064]), array([0.91260134]), array([0.10735208]), array([0.55708037]), array([0.6402967])]]
numpy? if yes, please update your tag.