3 ms·
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,
by worc3131 6y 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]])
- jonahx 6y agoThat 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.