# Printing an array without element type

**URL:** <https://discourse.julialang.org/t/printing-an-array-without-element-type/6731>\
**Category:** General Usage\
**Created:** [October 27, 2017, 9:38pm UTC](https://discourse.julialang.org/t/printing-an-array-without-element-type/6731 "2017-10-27T21:38:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [October 27, 2017, 9:38pm UTC](https://discourse.julialang.org/t/printing-an-array-without-element-type/6731/1 "2017-10-27T21:38:09Z")

</div>

For example, when I print an array of complex numbers, the result shows the element type as “Complex{Float64}”:

```julia
julia> c = rand(Complex128,3); println("c = $c")
c = Complex{Float64}[0.77556+0.100567im, 0.482976+0.657349im, 0.411924+0.0728219im]

```

Is there an easy way to prevent this information from showing up? In other words, I would like it to be

```julia
c = [0.77556+0.100567im, 0.482976+0.657349im, 0.411924+0.0728219im]

```

Of course, I can achieve this by something like

```julia
julia> println("c = $(string(c)[17:end])")
c = [0.77556+0.100567im, 0.482976+0.657349im, 0.411924+0.0728219im]

```

or even

```julia
julia> println("c = $(string(c)[length(string(eltype(c)))+1:end])")
c = [0.77556+0.100567im, 0.482976+0.657349im, 0.411924+0.0728219im]

```

but I am wondering if there is a cleaner way.

I notice that the element type is not printed if the element type is `Float64` or `Int64`:

```julia
julia> f = rand(3); println("f = $f")
f = [0.613025, 0.459371, 0.821628]

julia> i = rand(Int,3); println("i = $i")
i = [-8540970543845697954, 5703341344859102338, -5855558363139440179]

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 28, 2017, 7:49am UTC](https://discourse.julialang.org/t/printing-an-array-without-element-type/6731/2 "2017-10-28T07:49:12Z")

</div>

You have to implement printing somehow (unfortunately, I don’t think `Base.showarray` is modular enough to do what you want, but maybe someone will provide a solution using it). This is another way:

```julia
function show_vector_sans_type(io, v::AbstractVector)
    print(io, "[")
    for (i, elt) in enumerate(v)
        i > 1 && print(io, ", ")
        print(io, elt)
    end
    print(io, "]")
end

show_vector_sans_type(v::AbstractVector) =
    show_vector_sans_type(IOContext(STDOUT; :compact => true), v)

show_vector_sans_type(x)

```

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [October 28, 2017, 10:08am UTC](https://discourse.julialang.org/t/printing-an-array-without-element-type/6731/3 "2017-10-28T10:08:16Z")

</div>

@Tamas_Papp that is basically the type of function I am using in my Dendriform.jl package to print arrays.  
I think if you have a specific need for printing things in a package, it makes sense to just define your own.

Another complaint I had previously is the spaces that have been inserted into the syntax, as I explained here:

> [@Printing of Arrays without spaces](https://discourse.julialang.org/t/printing-of-arrays-without-spaces/6283):
>
> In previous version of Julia, printing an array was done without inserting spaces [8,7,6,5,4,3,2,1] Now in 0.6, it has spaces [8, 7, 6, 5, 4, 3, 2, 1] where can I find the method in Base that I would have to overwrite in my .juliarc.jl in order to modify the printing to be without the spaces? It’s preferred by me since certain matrices I need to print will be aligned more neatly without the spaces.

My solution was to modify the `Base.show_delim_array` function to get rid of the spaces. (not `showarray`)

---

<div class="post-metadata">

**Author:** ![Marcell\_Havlik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcell_havlik/32/37424_2.png) [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Post date:** [March 29, 2021, 10:20pm UTC](https://discourse.julialang.org/t/printing-an-array-without-element-type/6731/4 "2021-03-29T22:20:15Z")

</div>

Just a minor change in case someone else also want this pretty print on @Tamas_Papp solution.

This handles vectors in vectors, maybe it is useful for someone else too.

```julia
unction show_vector_sans_type(io, v::AbstractVector)
	print(io, "[")
	for (i, elt) in enumerate(v)
			i > 1 && print(io, ", ")
			if elt isa AbstractVector
				show_vector_sans_type(io, elt)
			else
				print(io, elt)
			end
	end
	print(io, "]")
end
show_vector_sans_type(v::AbstractVector) = show_vector_sans_type(stdout, v)

```
