Python Forum
Simplifying a rather short code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simplifying a rather short code
#2
Instead of 10 functions, I'd just have one. Then just have one variable full of all the circles.
def f(num, x):
    return (num/10) * np.exp(x*1j)

circles = []
for i in range(1, 11):
    circles.append([
        [f(i, n).real for n in np.linspace(0,2*np.pi,1000)],
        [f(i, n).imag for n in np.linspace(0,2*np.pi,1000)]
    ])

for circ in circles:
    plt.plot(*circ)

plt.show()
Or, you can skip the intermediary variable(s):
for i in range(1, 11):
    plt.plot(
        [f(i, n).real for n in np.linspace(0,2*np.pi,1000)],
        [f(i, n).imag for n in np.linspace(0,2*np.pi,1000)]
    )
plt.show()
Reply


Messages In This Thread
Simplifying a rather short code - by schniefen - Apr-06-2019, 04:38 PM
RE: Simplifying a rather short code - by nilamo - Apr-07-2019, 02:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simplifying the tie function blacklight 2 2,199 Jul-01-2020, 02:49 PM
Last Post: deanhystad
  Simplifying a short code schniefen 4 2,681 Apr-18-2019, 10:50 PM
Last Post: schniefen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020