How to get the range of valid Numpy data types?

前端 未结 2 709
感情败类
感情败类 2020-12-29 01:22

I\'m interested in finding for a particular Numpy type (e.g. np.int64, np.uint32, np.float32, etc.) what the range of all possible val

2条回答
  •  离开以前
    2020-12-29 01:46

    You can use numpy.iinfo(arg).max to find the max value for integer types of arg, and numpy.finfo(arg).max to find the max value for float types of arg.

    >>> numpy.iinfo(numpy.uint64).min
    0
    >>> numpy.iinfo(numpy.uint64).max
    18446744073709551615L
    >>> numpy.finfo(numpy.float64).max
    1.7976931348623157e+308
    >>> numpy.finfo(numpy.float64).min
    -1.7976931348623157e+308
    

    iinfo only offers min and max, but finfo also offers useful values such as eps (the smallest number > 0 representable) and resolution (the approximate decimal number resolution of the type of arg).

提交回复
热议问题