3 ms·
(shameful author here) One should read def rosen_explicit_loop(x): s = 0. n = x.shape[0] for i in range(0, n - 1): s += 100. * (x[i +
by serge-ss-paille 8y ago
(shameful author here)
One should read
def rosen_explicit_loop(x):
s = 0.
n = x.shape[0]
for i in range(0, n - 1):
s += 100. * (x[i + 1] - x[i] ** 2.) ** 2. + (1 - x[i]) ** 2
return s
(edited)
- chestervonwinch 8y ago... n = x.shape[0]
- quietbritishjim 8y agoOr just len(x). This works perfectly well on numpy arrays and has the bonus that it works on regular lists/tuples of floats, so the first snippet doesn't rely on numpy.