I am trying to remove sub-arrays from a multidimensional numpy array using a condition. In this exampe I want to remove all sub-arrays which include the value 999. Here is one of my failed attempts:
a = np.array([[[1,2,3], [1,2,3]],
[[999,5,6], [4,5,6]],
[[999,8,9], [7,999,9]]
])
for i in range(0,len(a)):
if 999 in a[i]:
np.delete(a, i, 0)
The result I want is:
array([[1,2,3], [1,2,3]])
This is just a smaler exaple, which should help me understand a lager issue, which loos like that:
# win_list_hyper.shape -> (1449168, 233)
# win_list_multi.shape -> (1449168, 12, 5, 5)
win_list_hyper = np.where(win_list_hyper <= 0, -3.40282e+38, win_list_hyper)
win_list_multi = np.where(win_list_multi <= 0, -3.40282e+38, win_list_multi)
# fail!:
for i in range(0,len(win_list_multi)):
if -3.40282e+38 in win_list_multi[i] or -3.40282e+38 in win_list_hyper[i]:
np.delete(win_list_multi, i, 0)
np.delete(win_list_hyper, i, 0)
(btw. if you know how to make this more efficient, please let me know aswell!)