how do I quickly convert all elements in a numpy array into fraction data type?

263 Views Asked by At

Just for a simple example, if I have an array like this:

data=np.array([[1/3,2/7],[3/5,5/6]])

Is there any quick way to convert it to the following without defining a function?

If we can't do it for an array, how about working with the list.

data=np.array([[Fraction(1,3), Fraction(2,7)],[Fraction(3,5),Fraction(5,6)]])
0

There are 0 best solutions below