Julia Array Notation
Note: This was originally published as an Observable notebook.
While writing guides for the Julia language I started using diagrams to explain and illustrate Julia arrays. The diagrams are useful as a way to visually represent fundamental array properties.
The first fundamental concept is dimension. In these diagrams, array dimension is represented by lines on the top and left sides of the array.
Column vectors, written as [1, 2, 3, 4]
, are one-dimensional:
Matrices, written as [1 2; 3 4]
, are two-dimensional:
Row vectors, written as [1 2 3 4]
, are, surprisingly, two-dimensional in Julia:
Zero-dimensional arrays can be drawn by omitting both dimension lines:
Another fundamental concept is an array's axes, which specify the valid indices along each dimension. In this notation the axes are labeled in gray on the outside of the array:
To draw arrays with nonstandard axes, change the labels. OffsetArrays allow you to offset the axes of any array:
OffsetArray([1, 2, 3, 4, 5], -2:2)
Higher-dimensional arrays are fully supported by Julia but their visual treatment in this notation is still an open question. Tensor notation might be a source of inspiration here.
The simplicity of this notation leaves room to improvise when illustrating a point. As an example, here is an explanation of broadcasting across two arrays. Hover over any array element to highlight its chain of provenance.