Hacker News new | ask | show | jobs
by worc3131 2140 days ago
This 100 character version is probably the cleanest.

    M = np.reshape(np.arange(16),(4,4))
    np.array([np.roll(M,(i,j),(0,1)) 
              for i in [1,0,-1]
              for j in [1,0,-1]])
1 comments

That requires you to break out of the array paradigm and drop back down to procedural looping. Which is what you'd expect since numpy is array operations bolted onto python as a library and J is array operations baked into the language itself.