0

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)]])
adfdsfsdf
  • 55
  • 4
  • To get a list (or object dtype array) with `Fraction` objects, you have to use a separate `Fraction(x,y)` call for each element. There's no "quilck" way. – hpaulj Aug 08 '22 at 15:48
  • And if you are trying to create this from the floats that your initial expression creates, how would you determine what numerator & denominator to use, especially w/ round off error? – Scott Hunter Aug 08 '22 at 15:49
  • ```data1 = [['1/3','2/7'],['3/5','5/6']] ``` ```[list(map(lambda x:Fraction(x),i)) for i in data1]``` just aworkarround – Deepan Aug 08 '22 at 16:09

0 Answers0