sta*_*biz -2 python pycocotools
这是getImgIds来自pycocotools:
pycocotools/coco.py:
def getImgIds(self, imgIds=[], catIds=[]):
'''
Get img ids that satisfy given filter conditions.
:param imgIds (int array) : get imgs for given ids
:param catIds (int array) : get imgs with all given cats
:return: ids (int array) : integer array of img ids
'''
imgIds = imgIds if _isArrayLike(imgIds) else [imgIds]
catIds = catIds if _isArrayLike(catIds) else [catIds]
if len(imgIds) == len(catIds) == 0:
ids = self.imgs.keys()
else:
ids = set(imgIds)
for i, catId in enumerate(catIds):
if i == 0 and len(ids) == 0:
ids = set(self.catToImgs[catId])
else:
ids &= set(self.catToImgs[catId])
return list(ids)
Run Code Online (Sandbox Code Playgroud)
这是test code的simulating值ids &= set(self.catToImgs[catId]):
fruits = set(['apple', 'banana', 'cherry'])
cars = set(['Ford', 'BMW', 'Volvo'])
fruits &= cars
print("fruits: len:{}, type: {}, values: {}".format(
len(fruits), type(fruits), fruits
))
Run Code Online (Sandbox Code Playgroud)
结果如下:
fruits: len:0, type: <class 'set'>, values: set()
Run Code Online (Sandbox Code Playgroud)
我得到的结果是len = 0.
&=如何理解上面的运算符对于类的意义set()呢?
小智 5
这可能有用:https://python-reference.readthedocs.io/en/latest/docs/sets/op_intersection.html
换句话说,&就是“按位与”运算符。使用语法&=,您就可以得到a &= b相当于a = a & b. 对于集合,它是两个集合的交集(如上面链接的文档中所述)。
如果两个集合中没有共同的元素,它将返回一个空集合。
| 归档时间: |
|
| 查看次数: |
178 次 |
| 最近记录: |