# How to display a sparse array on the REPL?

**URL:** <https://discourse.julialang.org/t/how-to-display-a-sparse-array-on-the-repl/113565>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [April 27, 2024, 1:33pm UTC](https://discourse.julialang.org/t/how-to-display-a-sparse-array-on-the-repl/113565 "2024-04-27T13:33:25Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 27, 2024, 1:44pm UTC](https://discourse.julialang.org/t/how-to-display-a-sparse-array-on-the-repl/113565/5 "2024-04-27T13:44:51Z")

</div>

> [@screw\_dog](#):
>
> The REPL uses basically just uses the `show` method to display output. So you can just use `show(x)` in your script

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)`](https://docs.julialang.org/en/v1/base/io-network/#Base.Multimedia.display) 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)`](https://docs.julialang.org/en/v1/base/io-network/#Base.show-Tuple%7BIO,%20Any,%20Any%7D) 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)`](https://docs.julialang.org/en/v1/base/io-network/#Base.show-Tuple%7BIO,%20Any%7D) is the default simple text representation of `x`. It is what is used by [`repr(x)`](https://docs.julialang.org/en/v1/base/strings/#Base.repr-Tuple%7BAny%7D), and is typically the format you might use to _input_ `x` into Julia. The 1-argument `show(x)` calls `show(stdout, x)`.
- [`print(x)`](https://docs.julialang.org/en/v1/base/io-network/#Base.print) 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](https://github.com/JuliaLang/julia/pull/54547)).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-display-a-sparse-array-on-the-repl/113565)._
