I discovered that numpy.where behaves differently when applied on a condition such as foo==2 when foo is a list or foo is a numpy.array
foo = ["a","b","c"]
bar = numpy.array(["a","b","c"])
numpy.where(foo == "a") # Returns array([])
numpy.where(bar == "a") # Returns array([0])
I want the same command to make this applicable to either list or numpy.array, and I am concerned about how to perform this efficiently. Is the following ok ?
numpy.where(numpy.array(foo, copy=False) == "a") # Returns array([0])
numpy.where(numpy.array(bar, copy=False) == "a") # Returns array([0])
Result is as expected, but is this the best way to answer my need ? Using each time numpy.array constructor is the best way to ensure object type ?
Thanks !
foo == "a"andbar == "a"and notnp.where. Lists do not behave like numpy arrays. Expecting anything butFalsefrom["a","b"] == "b"is as absurd as expectinglist() == str()to give an array.