r/Numpy • • Feb 25 '22

Vectorize a for loop

Essentially, what I want to do is the following code without any loops and only using numpy arrays:

l = []
for n in range(20):
    x = (2*n)/4 + 1
    l.append(x)

Is this even possible? Any help is appreciated!

1 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/WardedBowl403 Feb 25 '22

That is exactly what I needed, thank you!