np.linsapce Typerror

13 views
Skip to first unread message

Yang Liu

unread,
Sep 3, 2022, 5:28:22 PM9/3/22
to sympy
Hi,

I want to write a for loop to calculate all possible values, so I declare
m=a/b  #my test case a/b==3/2
r=np.linspace(0,m,10,dtype=float)
for i in range(len(r)):
      f(Fraction.from_float(r[i]))

where f is some function I write to print out some function space.
But I get 
TypeError: Cannot interpret '1.50000000000000' as a data type

Any idea on how why I get the error? 

If I cast m= float(a/b), I can work it out. However, Fraction.from_float(r[i]) in this case will not result in a fraction. 

Yang Liu

unread,
Sep 3, 2022, 5:59:27 PM9/3/22
to sympy
Also, I encounter

TypeError: Fraction.from_float() only takes floats, not 0.0400000000000000 (Float)

This seems even weirder. I specify it as a float
Reply all
Reply to author
Forward
0 new messages