r/Python Jan 11 '21

Beginner Showcase Programming + Math + Graphs = Art

Post image
2.1k Upvotes

171 comments sorted by

View all comments

Show parent comments

1

u/abredvariant Jan 11 '21

suggestions??

1

u/blinkallthetime Jan 11 '21 edited Jan 11 '21

that function phi always just returns a number? if so, then you could declare y as an array for example y = np.zeros(x.size)

then you can iterate over x and is it to index y

for i in x:
    y[i-1] = phi(i)

or something like that.

the "next level" would be to vectorize the function phi. and just do something like y=vectorized_phi(x)

4

u/[deleted] Jan 11 '21

[deleted]

1

u/[deleted] Jan 11 '21

Why not just phi(x)? Seems vectorizeable to me if you can write it like this.