numpy array with dtype Decimal?

前端 未结 3 1750
再見小時候
再見小時候 2020-11-29 09:30

Are Decimal dtypes available in numpy?

>>> import decimal, numpy
>>> d = decimal.Decimal(\'1.1\') 
>>> s = [[\'123.123\',\'23\'],[         


        
3条回答
  •  没有蜡笔的小新
    2020-11-29 09:42

    Unfortunately, you have to cast each of your items to Decimal when you create the numpy.array. Something like

    s = [['123.123','23'],['2323.212','123123.21312']]
    decimal_s = [[decimal.Decimal(x) for x in y] for y in s]
    ss = numpy.array(decimal_s)
    

提交回复
热议问题