Using numpy vector elements in a Fraction module in Python

I try to use elements from a numpy array as input for a module Fraction, and I get the following error: "TypeError: both arguments must be Rational instances"

For example, if:

Y  =  np.array([7,1], dtype='int64')  
X  =  Y[0]*3+Y[1]

And then:

a = Fraction(58,X)  

I get the same error. I also tried to do with X=X.astype('int')or X=X.astype('int32')without success.

What do I need to do to convert the numpy array to the "Rational instance" that is needed for the Fraction module?

+5
source share
1 answer

, -, , Numpy Python ( , 32- 64- Python, dtype='int' np.int32 np.int64, Python int).

Python int :

Fraction(58, int(X))
+5

All Articles