News for hackers. Stuff that matters.
Re:J Notation as a Tool of Thought by jonahx on Saturday August 15, 2020 @12:00PM (#24169823)
I have only passing experience with numpy, but I suspect the following "shift a matrix in all 8 directions", used in the famous APL/J game of life solution [0][1], would require multiple statements as well as being more verbose in numpy (I'm guessing you'd need to use "roll" multiple times?):

    (>,{;~i:1) |. i.4 4
Try it online: https://tio.run/##y/r/PzU5I19Bw06n2rou08pQU6FGTyFTz0TB5P9/AA

[0] https://www.youtube.com/watch?v=a9xAKttWgP4&t=5s

[1] https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/NWJtjb...

Re:J Notation as a Tool of Thought by worc3131 on Saturday August 15, 2020 @03:15PM (#24171442)
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]])
Re:J Notation as a Tool of Thought by jonahx on Saturday August 15, 2020 @06:13PM (#24172884)
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.