Reading Julia

ISE 754 · a self-test on the Julia in the lectures

Each item shows a few lines of Julia taken from a lecture and asks what one expression evaluates to, or what one line does. Predict first, then pick. The skill being built is reading: the assistant writes the code; the reader's job is to know what it computed, well enough to check it, change a parameter, and try an edge case. Every answer here was computed by running the code, not typed in.

One construct at a time is the faster way in when a particular piece of syntax is the problem. Every row of the syntax card below is numbered; enter that number here, or click it on the card, and the questions are drawn from that construct alone.

Items from:
·

The syntax card

Every construct the published lectures use, in the order a reader meets it, with the lecture that introduces it. Reading Julia in this course means recognizing these on sight. Click a number to be quizzed on that construct alone, or type it into the box at the top of the page.

#ConstructHow to read itFirst used
1a = [1, 2, 3]a vector; commas separate elements1.2 Sec. 1.3
2A = [1 2; 3 4]a matrix; spaces separate columns, ; ends a row1.2 Sec. 1.3
31:5, 1:2:5, [1:5;]a range start:stop or start:step:stop; the ; in brackets expands it into a vector1.2 Sec. 1.3
4[f(i) for i in 0:5]an array comprehension: evaluate once per i, collect the results1.2 Sec. 1.3
5a[3], a[[2, 4]], a[end]indexing from 1; an index array picks several; end is the last1.2 Sec. 1.3
6A[1, 2], A[:, 1], A[1, :]row, column; : selects an entire row or column1.2 Sec. 1.3
7a[2:end], a[1:end-1]slices: drop the first, drop the last1.2 Sec. 1.3
82 .+ a, a .^ 2, f.(a)the dot broadcasts: apply to each element; 2a needs no dot1.2 Sec. 1.4
9sum(a), cumsum(a)add all elements; the running total1.2 Sec. 1.4
10sum(A, dims = 1)sum down each column (dims = 2: across each row)1.2 Sec. 1.4
11a .> 0, .&, .|a true/false mask, one entry per element; combined elementwise1.2 Sec. 1.5
12a[a .> 0], findall(a .> 0)keep the elements where true; the positions where true1.2 Sec. 1.5
13sort, sortperm, argminvalues in order; the indices that sort them; the position of the smallest1.2 Sec. 1.5
14t = (6, 1, 4)a tuple, a fixed group of values, indexed like a vector1.2 Sec. 1.6
15function f(a) … return c enda multi-line function; return hands back the value1.2 Sec. 1.7
16f(a) = 3a + 1a one-line function1.2 Sec. 1.7
17w -> w > 10an anonymous function, read “w maps to w > 10”1.2 Sec. 1.7
18filter(test, a)keep the elements for which the test is true1.2 Sec. 1.7
19A \ bleft division: solve A x = b1.2 Sec. 1.8
20using DataFramesload a package1.2 Sec. 1.9
21DataFrame(x = …, y = …), df.xa table of named columns; one column back as a vector1.2 Sec. 1.10
22x0 = [4.0, 2.0] vs [x0]in a broadcast, brackets hold a whole vector fixed so it pairs with each element of the other argument2.2
23eachrow(P)the rows of a matrix (or table), one at a time2.2
24f(x; dims = 1), round(x, digits = 1)keyword arguments: named options after the positional ones2.2
25c ? a : bone-line if: a when c is true, else b2.2
26c && return x, c && continueshort-circuit: the right side runs only when c is true, so also a one-line if2.2, 2.3
27optimize(f, x0).minimizerthe point found by the search that starts at x0; .minimum is the value there2.2
28filter(r -> r.POP > 0, df)keep the rows r of the table for which the test holds2.2
29:NC, :POPa Symbol: a name used as a value, e.g. a state or a column2.2
30a, b = 1, 2two names assigned at once, left to right2.3
31push!(v, x), filter!the ! warns that the function changes its argument1.3, 2.4
32Int[], Float64[]an empty vector that will hold that type1.3, 2.4
3312e6, 200_00012 × 10⁶; underscores are digit separators for the reader2.4
34round(Int, x)round to the nearest integer, returned as an Int2.4
35hcat(lon, lat), vcatside by side as columns; stacked end to end2.5
36:POP => sum => :POPcolumn => function => new name: a computed column2.5
37prt(df)Logjam's table print, the course's way of showing a table2.2
38xᵒ, TCᵒ, σ, tₑUnicode is part of the name: marks an optimal value; typed by tab completion, x\^o Tab1.2 Sec. 1.2

Using the assistant as a tutor

For more practice than this page holds, hand any lecture code block (or a whole companion script) to Claude with the prompt below. It turns the assistant into a reading tutor that asks rather than writes; it works in Claude Code or in a chat window.