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?

Answer:1

**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.

Answer:2

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-op.

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

Keep in mind that because the elements of the array are Python objects, you won't get much of a speed up using them. For example, if you try to add this to any other array, the others 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.

Answer:3

- python numpy array with random numbers
- python numpy array with same value
- python numpy array with different data types
- python numpy array with strings
- python numpy array with zeros
- python numpy array with value
- python numpy array with size
- python numpy array with shape
- python numpy array with nan
- python numpy array with ones
- python numpy array with range
- python numpy array with indices
- python numpy array to list
- python numpy array to image
- python numpy array to csv
- python numpy array to dataframe
- python numpy array to tuple
- python numpy array to pandas dataframe
- python numpy array to json
- python numpy array to file

For example, I may use python setup.py build --compiler=msvc or python setup.py build --compiler=mingw32 or just python setup.py build, in which case the default compiler (say, bcpp) will be used. How ...

For example, I may use python setup.py build --compiler=msvc or python setup.py build --compiler=mingw32 or just python setup.py build, in which case the default compiler (say, bcpp) will be used. How ...

I use pydicom library to generate .dcm files using the datasets coming from the CT and MRI machines, however in that dataset, the tag (0002,0010) is missing. As I dont have that tag, I am not able to ...

I use pydicom library to generate .dcm files using the datasets coming from the CT and MRI machines, however in that dataset, the tag (0002,0010) is missing. As I dont have that tag, I am not able to ...