# Simplify signature of printed arrays

**URL:** <https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025>\
**Category:** General Usage\
**Tags:** arrays, unitful\
**Created:** [November 5, 2021, 7:45pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025 "2021-11-05T19:45:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 5, 2021, 7:45pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025/1 "2021-11-05T19:45:08Z")

</div>

When one prints a simple array of floats, one gets:

```julia
julia> println(ones(3))
[1.0, 1.0, 1.0]

```

However, if I print an arrays of unitful quantities, I get:

```julia
julia> println(ones(3)u"nm")
Quantity{Float64, 𝐋, Unitful.FreeUnits{(nm,), 𝐋, nothing}}[1.0 nm, 1.0 nm, 1.0 nm]

```

Is there a way (shouldn’t it?) print only `[1.0 nm, 1.0 nm, 1.0 nm]` without doing type-piracy?

Being clear: I don’t want to change my implementation of the `show `methods of my types to adapt specifically to `Unitful` types. `Unitful` is not a dependency, just a nice thing to have. The thing is that some printouts, like this:

```julia
julia> box = Box(ones(3),0.1)
Box{OrthorhombicCell, 3, Float64, Float64, 9}
  unit cell matrix: [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]
  cutoff: 0.1
  number of computing cells on each dimension: [12, 12, 12]
  computing cell sizes: [0.1, 0.1, 0.1] (lcell: 1)
  Total number of cells: 1728

```

become way too ugly:

```julia
julia> box = Box(ones(3)u"nm",0.1u"nm")
Box{OrthorhombicCell, 3, Quantity{Float64, 𝐋, Unitful.FreeUnits{(nm,), 𝐋, nothing}}, Quantity{Float64, 𝐋^2, Unitful.FreeUnits{(nm^2,), 𝐋^2, nothing}}, 9}
  unit cell matrix: Quantity{Float64, 𝐋, Unitful.FreeUnits{(nm,), 𝐋, nothing}}[1.0 nm 0.0 nm 0.0 nm; 0.0 nm 1.0 nm 0.0 nm; 0.0 nm 0.0 nm 1.0 nm]
  cutoff: 0.1 nm
  number of computing cells on each dimension: [12, 12, 12]
  computing cell sizes: Quantity{Float64, 𝐋, Unitful.FreeUnits{(nm,), 𝐋, nothing}}[0.1 nm, 0.1 nm, 0.1 nm] (lcell: 1)
  Total number of cells: 1728

```

Any suggestion?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 5, 2021, 8:12pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025/2 "2021-11-05T20:12:53Z")

</div>

May be too basic for what you need, but just in case:

```julia
using Unitful
v = ones(3)u"nm"
println(ustrip(v), unit(v[1]))
[1.0, 1.0, 1.0]nm

```

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [November 5, 2021, 8:14pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025/3 "2021-11-05T20:14:54Z")

</div>

There is

```julia
function show(io::IO, x::Unit{N,D}) where {N,D}
    show(io, FreeUnits{(x,), D, nothing}())
end

```

but unfortunately I didn’t find a specialization for `FreeUnits`. So maybe an oversight?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 5, 2021, 9:51pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025/4 "2021-11-05T21:51:41Z")

</div>

This seems simple and closer to your original request:

```julia
using Unitful
v = ones(3)u"nm"
println('[', join(v,", "), ']')
[1.0 nm, 1.0 nm, 1.0 nm]

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 5, 2021, 10:59pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025/5 "2021-11-05T22:59:27Z")

</div>

Another way using tuples:

```julia
using Unitful
v = ones(3)u"nm"
println(tuple(v...))
(1.0 nm, 1.0 nm, 1.0 nm)

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 5, 2021, 11:30pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025/6 "2021-11-05T23:30:56Z")

</div>

Nice, this one is quite generic, may be a good alternative. I will test it. Thanks @rafael.guerra, something like you suggested above did the trick.
