J Notation as a Tool of Thought
hillelwayne.com
J Notation as a Tool of Thought
1–10 of 60 posts
Re: J Notation as a Tool of Thought
#2>> np.array([1, 2, 3]) * 2
array([2, 4, 6])
>>> np.array([1, 2, 3]) * np.array([4, 5, 6])
>>> np.arange(0, 16).reshape(4, 4) + np.array([5, 5, 5, 5])
array([[ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]])
Re: J Notation as a Tool of Thought
#3Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…
------------------------------------------------------------------------
Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions:- No iteration (including implicit iterations—map, filter; reduce is ok)
- No loops whatsoever. Recursion is ok, but should be avoided wherever possible.
- No explicitly named arguments; everything in pointfree style.
(I know, map/filter can be implemented recursively. But compared with the equivalent constructs in apl, they're about 10× as verbose, and harder to reason about and understand. Even reduce is somewhat of a gimme.)
Re: J Notation as a Tool of Thought
#4Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…
Re: J Notation as a Tool of Thought
#5Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…
You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance. ------------------------------------------------------------------------ Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions: - No iteration (including implicit iterations—map, filter; reduce is ok) -…
Re: J Notation as a Tool of Thought
#6Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…
The philosophy behind array languages runs much deeper than adding two arrays or transposing matrices.
Re: J Notation as a Tool of Thought
#7Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…
You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance. ------------------------------------------------------------------------ Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions: - No iteration (including implicit iterations—map, filter; reduce is ok) -…
>>> np.array([10, 20, 30]) + np.array([[1,2,3], [4,5,6], [7,8,9]])
array([[11, 22, 33],
[14, 25, 36],
[17, 28, 39]])
Sieves exist in numpy, called masks: >>>np.array([10, 20, 30]) > 15
array([False, True, True])
Of course they can be operated on just like any other numpy array.Grades exist in numpy:
>>>np.array([5,4,3,2,1]).argsort()
array([4, 3, 2, 1, 0])
Of course they are a little more verbose since all of those operations are from the library and not native to python.Re: J Notation as a Tool of Thought
#8Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…
Comparing numpy to J is like comparing a dirty rag to a designer suit. The examples you've listed are trivial; the power of J and other array languages cannot be appreciated from afar. The philosophy behind array languages runs much deeper than adding two arrays or transposing matrices.
Re: J Notation as a Tool of Thought
#9Earlier quoted context omitted.
You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance. ------------------------------------------------------------------------ Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions: - No iteration (including implicit iterations—map, filter; reduce is ok) -…
Rank Is actually implicitly done by numpy using a mechanism called broadcasting. For example: >>> np.array([10, 20, 30]) + np.array([[1,2,3], [4,5,6], [7,8,9]]) array([[11, 22, 33], [14, 25, 36], [17, 28, 39]]) Sieves exist in numpy, called masks: >>>np.array([10, 20, 30]) > 15 array([False, True, True]) Of course they can be operated on just like any other numpy array. Grades exist in numpy: >>>np.array([5,4,3,2,1])…
>>> arr = np.array([10, 20, 30])
>>> arr[arr > 15]
array([20, 30])
Re: J Notation as a Tool of Thought
#10I however always thought having an array as the primitive in R was great only because R is focused on statistics and data science.
My understanding is that J claims to be general purpose programming and as such I’m surprised the paradigm holds.