Answer the question
In order to leave comments, you need to log in
What is wrong with the Decimal() constructor?
Now it's my turn to ask stupid questions. Meditate on this:
import numpy as np
from decimal import Decimal
t = tuple(np.square(Decimal(123).as_tuple().digits))
assert t == (1, 4, 9)
assert type(t) is tuple
assert type(t) == type((1, 4, 9))
Decimal((0, (1, 4, 9), 0))
Decimal((0, t, 0))
Answer the question
In order to leave comments, you need to log in
The bottom line is that here
Checking the tuple, not its elements.
>>> type(t[0])
<class 'numpy.int32'>
numpy
. I'm not good at numpy
, from the word in general, so the dumbest, but working solution that immediately came to my mind:>>> Decimal((0, tuple([int(x) for x in t]), 0))
Decimal('149')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question