An array with a mix of numbers and lists (empty or not) is object dtype. This is practically a list; fast compiled numpy math no longer works. The only practical alternative to a list comprehension is np.frompyfunc.
Write a small function that can distinguish between a number and list and length of list, and apply that to the array. If it returns True for an empty list, then np.where will identify the location
In [41]: myList1 = np.array([1,1,1,[1],1,1,[1],1,1])
...: myList2 = np.array([1,1,1,[],1,1,[],1,1])
Develop a function that returns True for a empty list, False otherwise:
In [42]: len(1)
...
TypeError: object of type 'int' has no len()
In [43]: len([])
Out[43]: 0
In [44]: def foo(item):
...: try:
...: return len(item)==0
...: except TypeError:
...: pass
...: return False
...:
In [45]: foo([])
Out[45]: True
In [46]: foo([1])
Out[46]: False
In [47]: foo(1)
Out[47]: False
Apply it to the arrays:
In [48]: f=np.frompyfunc(foo,1,1)
In [49]: f(myList1)
Out[49]:
array([False, False, False, False, False, False, False, False, False],
dtype=object)
In [50]: np.where(f(myList1))
Out[50]: (array([], dtype=int64),)
In [51]: np.where(f(myList2))
Out[51]: (array([3, 6]),)
dtype.numpything; it works for me after updating to 1.16.