This is a fundamentals-related question so it might appear very dumb for other people but here it goes:
From reading the docs and this post, I understand that np.where()
returns an empty array for y
if the passed argument array is 1D. But how can I check if it is actually an empty array, rather than being None
or NaN
?
I have checked this post to check for Noneness
, but I'm stumped on how to do this if I can't access the returned value in the first place. I tried to access this value (see below code) but I get an IndexError
Moreover, I'm a little confused on the inner workings of numpy.where()
. From the docs it says that np.where() returns an ndarray but it returns a tuple if I run it on Jupyter.
The following is the code I used. (numpy version: numpy==1.15.4)
test_array = np.array([4, 5, 6]) # 1-D array
print(type(test_array))
>>> <class 'numpy.ndarray'>
thres = 6
result = np.where(test_array > thres)
print(type(result))
>>> <class 'tuple'>
Related to the question above, if I try to access the result values,
result
>>> (array([], dtype=int64),)
result[0]
>>> array([], dtype=int64)
result[1]
>>> IndexError: tuple index out of range
Please let me know if I'm missing something!
Thanks in advance!