Are Decimal ‘dtypes’ available in NumPy?

NumPy doesn’t recognize decimal.Decimal as a specific type. The closest it can get is the most general dtype, object. So when converting the elements to the desired dtype, the conversion is a no operation.

>>> ss.dtype
dtype('object')

Keep in mind that because the elements of the array are Python objects, you won’t get much of a speedup using them. For example, if you try to add this to any other array, the other elements will have to be boxed back into Python objects and added via the normal Python addition code. You might gain some speed in that the iteration will be in C, but not that much.

Leave a Comment