I'm trying to write a sine function that outputs answers going only to two decimal places. This is my code so far:
x=np.arange(0,190,10)
x_values=np.deg2rad(x)
y=np.sin(x_values)
y_values={":.2f"}.format(y)
print(y_values)
All the code through y works for me, when I do
print(y)
it outputs the correct values, but to like 10 decimal places, and I'd like to limit it to 2. I would like to do it using the .format notation, which I suck at. I'm getting an error that says "'set' object has no attribute 'format'," so there's some kind of fundamental misunderstanding I have about exactly how .format works. Is it only meant for strings? I would greatly appreciate any help I can get.
I did have a successful result using this:
y_values=[ '%.2f' % elem for elem in y ]
However, I'd like to see if it's possible to do it with .format. Thank you!