python函数参数冒号_Python3 - 参数中的冒号和箭头

Python3.5 中新增了一个功能是类型提示(type hints) -冒号后面是建议传入的参数类型

箭头后面是建议函数返回的类型

如:def greeting(name: str) -> str:

return 'Hello ' + name

该代码块指明了,输入参数 name 为 str 类型;且该函数的输出结果也为 str 类型.

注:类型提示并非强制规定和检查,即,即使传入的实际参数与建议参数不符,也不会报错. 如:def value_sum(a: int, b: int=100) -> int:

sum = a + b

return sum

#

print(value_sum(1, 2)) # out: 3

print(value_sum('1', '2')) # out: '12'

1. codeblockimport numpy as np

import pycocotools.mask as mask_utils

from typing import List

def polygons_to_bitmask(

polygons: List[np.ndarray],

height: int,

width: int) -> np.ndarray:

"""

Args:

polygons (list[ndarray]): each array has shape (Nx2,)

height, width (int)

Returns:

ndarray: a bool mask of shape (height, width)

"""

assert len(polygons) > 0, "COCOAPI does not support empty polygons"

rles = mask_utils.frPyObjects(polygons, height, width)

rle = mask_utils.merge(rles)

return mask_utils.decode(rle).astype(np.bool)

2. 参考

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值