numpy where with array of tuples
问题 Why can't I find the location of a tuple in an array? Afterall, the bottom expression prints True foo = numpy.array([(5, 30), (5,), 5]) bar = numpy.where(foo==foo[0]) print(bar) Prints (array([], dtype=int64),) print((5,30)==foo[0]) Prints True 回答1: It's because: import numpy foo = numpy.array([(5, 30), (5,), 5]) bar = numpy.where(foo==foo[0]) print(foo==foo[0]) False That's why you're getting an empty array. A list comprehension alternative is [v for v in foo if v == foo[0]] will result in [