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
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 [(5, 30)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.