Hacker News new | ask | show | jobs
by serge-ss-paille 2983 days 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)
1 comments

...

    n = x.shape[0]
Or 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.