# Julia type displaying change between versions

**URL:** <https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029>\
**Category:** New to Julia\
**Created:** [July 30, 2022, 2:35pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029 "2022-07-30T14:35:04Z")\
**Posts on this page:** 10\
**Page:** 3

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 1, 2022, 6:45pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/41 "2022-08-01T18:45:49Z")

</div>

> [@Schneeschaufel](#):
>
> I know and this was my point. An array consists of vectors of vectors etc.

This is the _opposite_ of my point. An array in julia is _not_ a vector of vectors. These are different concepts; they are different in memory layout, implementation, which operations they support, and also from a linear algebra perspective. They are _similar_, and therefore a `Vector` is a subtype of `Array`, but they are not identical.

> [@Schneeschaufel](#):
>
> Yes the vectors have to return the same length.

And what if they don’t? After all, each element in a list can be totally distinct in length. Is it really fair to say, _at a type level_, that an object that has direct correspondence with math and tensors is the same as all lists of lists? If you do this, everywhere you use a Matrix you must check it is valid before e.g. accessing indices. No thanks.

The only point I agree with you on in this thread is that numpy isn’t easy to use in this regard:

```python
In [57]: x = np.array([[1,2], [1,2]])

In [58]: y = np.array([[1,2], [1,2,3]])

In [59]: x.ndim
Out[59]: 2

In [60]: y.ndim
Out[60]: 1

In [61]: x[0,0]
Out[61]: 1

In [62]: y[0,0]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-62-74d735007e1b> in <module>()
----> 1 y[0,0]

IndexError: too many indices for array

```

It is confusing to me that the above constructor makes two completely different objects in the two cases. `x` is a Matrix, in the julia sense, while `y` is a 1-d np.ndarray containing two regular python lists. In my opinion (coming from julia), whether I want a list of lists in the first case, or whether I am asking for a matrix in the second (and an error should be thrown) is something that should be more explicit, and after the construction, I should be certain what I have created.

It’s worth noting that your original post in this thread was based on a misunderstanding of what changed between julia versions. It seems that you believed that in past versions, matrices were stored as a list of lists, because the printout said `Array{Float64, 2}`, and the word array shows up in other languages as well. As I hope is clear by now: this was never the case. Julia has always distinguished between these concepts, and that distinction is fundamental to its usefulness in mathematical programming. The only thing that changed is the word Matrix shows up in the printout now, to help users quickly understand what the object is (and always was).

I’m not sure how much exposure you have to the language so far, but I think that greater immersion in the language, including reading documentation and previous discussions, here and on github, will demonstrate that the core decisions behind julia are all perfectly sound, to say the least.

---

<div class="post-metadata">

**Author:** ![Schneeschaufel](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@Schneeschaufel](https://discourse.julialang.org/u/Schneeschaufel)\
**Post date:** [August 1, 2022, 7:23pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/42 "2022-08-01T19:23:21Z")

</div>

Numpy’s y makes perfect sense.

But I admit it can be annoying to debug (I have spent more time doing it than I want to admit) especially if you accumulate sub-arrays in a list only for later to find out when you are about to convert it into an array that some elements don’t share a common dimension.

But then in real life outside of universities not everything is laid out perfectly especially when dealing with real data.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 1, 2022, 7:57pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/43 "2022-08-01T19:57:27Z")

</div>

> [@Schneeschaufel](#):
>
> But then in real life outside of universities not everything is laid out perfectly especially when dealing with real data.

I find this response ridiculous, to be honest.  
This has nothing to do with universities or things being perfectly laid out. No one has ever had to debug this in Julia, because it simply can’t happen, end of story.

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [August 1, 2022, 9:24pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/44 "2022-08-01T21:24:51Z")

</div>

On the comment about numpy (when you pass it a ragged list of lists) IIIRC that behaviour is going to be deprecated and will raise an error in the future.

---

<div class="post-metadata">

**Author:** ![stephancb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephancb/32/14243_2.png) [@stephancb](https://discourse.julialang.org/u/stephancb)\
**Post date:** [August 2, 2022, 2:18pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/45 "2022-08-02T14:18:19Z")

</div>

Part of the confusion seems to originate from Numpy:

```python
>>> from numpy import *
>>> a = matrix('1 2; 3 4')
>>> a
matrix([[1, 2],
        [3, 4]])

```

In Numpy a matrix is a column vector of row vectors, at least it is printed like this. Let’s try a little “linear algebra”, multiplication of matrix and vector:

```python
>>> b=array([5, 6])
>>> b.shape = (2,1) # Turn it to a column vector (rather vector of vectors?)
>>> b
array([[5],
       [6]])
>>> a*b # Matrix times column vector
matrix([[17],
        [39]])
>>> c=array([7, 8]) # row vector times matrix?
>>> c*a                 
matrix([[31, 46]])

```

A bit strange, I would say, but perhaps it “kind of works”?

In Julia:

```julia
julia> a=[1 2;
          3 4]
2×2 Matrix{Int64}:
 1 2
 3 4
julia> b=[5, 6]
2-element Vector{Int64}:
 5
 6

julia> a*b # Matric times column vector:
2-element Vector{Int64}:
 17
 39

julia> c=[7 8]
1×2 Matrix{Int64}:
 7 8

julia> c*a
1×2 Matrix{Int64}:
 31 46

```

Relatively smooth “linear algebra” I would say?

---

<div class="post-metadata">

**Author:** ![Schneeschaufel](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@Schneeschaufel](https://discourse.julialang.org/u/Schneeschaufel)\
**Post date:** [August 2, 2022, 2:39pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/46 "2022-08-02T14:39:52Z")

</div>

I am not sure but I would probably use:

```julia
c=[7, 8]'

```

because differentiating between ‘,’ an no ‘,’ can become quite error prone in real code.

But in any case the above numpy code is a perfect example why numpy is a rats nest.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [August 2, 2022, 2:41pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/47 "2022-08-02T14:41:45Z")

</div>

I think this is a really nice example on the consistency that Julia provides here. One could also do

```julia
julia> c = [7,8]'
1×2 adjoint(::Vector{Int64}) with eltype Int64:
 7 8

```

to be more precise that `c` is a row vector (you get the same type out after multiplication then).

I like that Julia is more strict here in distinguishing matrices (`Array{T,2}`) or in other words – 2D rectangular data and not vectors of vectors (where the single vectors could be of different length).

Oh Schneeschaufel just wrote the same idea 🙂 but concerning numpy I am also quite biased, since I prefer the exactness Julia uses here.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 2, 2022, 4:48pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/48 "2022-08-02T16:48:42Z")

</div>

Anything actionable here? Seems like not. Printing of some types changed as part of a general overhaul to make printing of complex parametric types simpler and cleaner. Actual type information didn’t change, just printing of aliased parametric types. This can break some doctests, which is annoying, but doesn’t affect the behavior of code that isn’t reflecting on and relying on specific printing of types.

There also seems to be a long discussion about whether matrices are vectors of vectors. They aren’t, of course, but there’s some discussion about whether it’s a good idea to try to treat them as if they are to some extent. Numpy is forced to do this somewhat because they need to go back and forth between plain Python lists and real multidimensional arrays in numpy. This correspondence is required since they use Python lists as the literal syntax for numpy arrays and Python doesn’t have multidimensional lists, so the only option for using lists to represent multidimensional arrays is to use a lists of lists. Of course, Numpy doesn’t go all the way, which we can see from [this example](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/41) since `x` and `y` have very different APIs. If Numpy was truly committed to treating matrices and vectors of vectors the same way then `y[0,0]` would be a valid way to index into a vector of vectors and `x[0][0]` would be a valid way to index into a matrix. I’ll note that I also have my usual strong distaste for the fact that what the code means depends on a dynamic runtime property—whether all the vectors in your vector of vectors happen to have the same length or not. This is a classic footgun where code goes 💥 in some special case you probably didn’t expect. How do you force Numpy to actually give you a vector of vectors when that’s what you want, even if they all happen to have the same length?

Julia is in a quite different situation since the standard array type is multidimensional and the language has direct syntax for n-dimensional array literals. So there’s no reason to use nested arrays as a bad proxy for real multidimensional arrays. It’s interesting that a limitation of Python has somehow become interpreted from one point of view as a virtue. It’s all about what you’re used to, I suppose.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [August 2, 2022, 5:01pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/49 "2022-08-02T17:01:30Z")

</div>

One needs to draw a line in the sand and decide what things are part of your API promise for semantic versioning and what are not.

The [ColPrac contributors guide](https://github.com/SciML/ColPrac#changes-that-are-not-considered-breaking) formalizes this for many julia projects.  
While not officially for julia itself, the list of what is and is not part of the API promise was informed by discussions with core julia developers of what they considered breaking (as well as the equivalent document for the TensorFlow project).

> Everything on this list can, in theory, break users’ code.  
> See [XKCD#1172](https://xkcd.com/1172/).  
> However, we consider changes to these things to be non-breaking from the perspective of package versioning.  
> …
> 
> - **Changes to the string representation:** The output of `print`/`string` or `show`/`repr` on a type may change at any time.  
> Users should not depend on the exact text, but rather on the meaning of the text.  
> Changing the string representation often breaks downstream packages tests, because it is hard to write test-cases that depend only on meaning

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 10, 2022, 9:14pm UTC](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029/50 "2022-08-10T21:14:37Z")

</div>

Split this topic on August 10, 2022, 9:14pm UTC

4 posts were split to a new topic: [Numpy’s list of lists vs. Julia’s linear indexing](https://discourse.julialang.org/t/numpys-list-of-lists-vs-julias-linear-indexing/85596)

[Previous page](https://discourse.julialang.org/t/julia-type-displaying-change-between-versions/85029.md?page=2)
