Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
z [i] = 1 /(1 + i)となるようにnumpyにベクトルzを作成する必要があります。以下のコードでそれを行うより速い方法はありますか?
import numpy as np n = 10000 z = np.zeros(n) for i in xrange(n): z[i] = 1.0/(1 + i)
最速の方法:
z = 1.0/np.arange(1, n+1)
どうですか:
z = np.arange(n) z = 1/(1+z)