Issue
Are Decimal dtypes available in numpy?
>>> import decimal, numpy
>>> d = decimal.Decimal('1.1')
>>> s = [['123.123','23'],['2323.212','123123.21312']]
>>> ss = numpy.array(s, dtype=numpy.dtype(decimal.Decimal))
>>> a = numpy.array(s, dtype=float)
>>> type(d)
<class 'decimal.Decimal'>
>>> type(ss[1,1])
<class 'str'>
>>> type(a[1,1])
<class 'numpy.float64'>
I suppose numpy.array doesn't support every dtype, but I sort of thought that it would at least let a dtype propagate as far as it could as long as the right operations were defined. Am I missing something? Is there some way for this to work?
Solution
IMPORTANT CAVEAT: THIS IS A BAD ANSWER
So I answered this question before I really understood the point of it. The answer was accepted, and has some upvotes, but you would probably do best to skip to the next one.
Original answer:
It seems that Decimal
is available:
>>> import decimal, numpy
>>> d = decimal.Decimal('1.1')
>>> a = numpy.array([d,d,d],dtype=numpy.dtype(decimal.Decimal))
>>> type(a[1])
<class 'decimal.Decimal'>
I'm not sure exactly what you are trying to accomplish, your example is more complicated than is necessary for simply creating a decimal numpy array.
Answered By - Eric Wilson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.