mercredi 5 avril 2017

How to optimize code in Python? Vectorize?

Suppose I have a vector myVec and I want to sum 1260 elements of it for 10 000 times.

I wrote the following code:

newVector = [sum(np.random.choice(myVec, 1260, replace=True)) for _ in range(10000)]

how can I optimize it and save time?

Can I vectorize the code?




Aucun commentaire:

Enregistrer un commentaire