How to display a sparse array on the REPL?

No, this is wrong. The 1-argument show(x) (which is also called by print(x) for most types) calls the 2-argument show(stdout, x). For matrices, this is less verbose than the 3-argument show(stdout, "text/plain", x) called by the REPL’s display.

Summary:

  • display(x) tells the current environment to display x in whatever way it thinks best. This might be a graphical display in something like a Jupyter notebook. By default (e.g. in scripts or in the text REPL), it calls show(io, "text/plain", x) or equivalently show(io, MIME"text/plain"(), x) for an appropriate io stream. (In the REPL, io is an IOContext wrapper around stdout.) The REPL uses display to output the result of an evaluated expression.
  • The 3-argument show(io, ::MIME"text/plain", x) method is verbose pretty-printing of x. By default (if no verbose method is defined for typeof(x)), it calls the 2-argument show(io, x).
  • The 2-argument show(io, x) is the default simple text representation of x. It is what is used by repr(x), and is typically the format you might use to input x into Julia. The 1-argument show(x) calls show(stdout, x).
  • print(x) calls print(stdout, x), which by default calls show(stdout, x). It mainly differs from show when x is a string, where print outputs the raw text but show outputs an escaped string enclosed in quotation marks.

Update May 2024: a version of this summary should be added to the manual (julia#54547).

3 Likes