Type hinting / annotation (PEP 484) for numpy.ndarray

前端 未结 5 992
旧时难觅i
旧时难觅i 2020-12-14 14:03

Has anyone implemented type hinting for the specific numpy.ndarray class?

Right now, I\'m using typing.Any, but it would be nice to have something more specific.

5条回答
  •  伪装坚强ぢ
    2020-12-14 15:05

    What i did was to just define it as

    Dict[Tuple[int, int], TYPE]

    So for example if you want an array of floats you can do:

    a = numpy.empty(shape=[2, 2], dtype=float) # type: Dict[Tuple[int, int], float]

    This is of course not exact from a documentation perspective, but for analyzing correct usage and getting proper completion with pyCharm it works great!

提交回复
热议问题