Array type modification

As far as I can tell, what you want to do is work with matrix algebra. That’s fine. But then you need to keep the Vector type out of it, and just stick with matrices. It takes some extra care because of the way slicing works, but then you will have the sort of consistent behaviour that you want.

Good luck.

No it’s not. And in any mathematically rigorous course a lot of time is spent so that way students learn this is not true. A vector is isomorphic to an Nx1 matrix but it is not an Nx1 matrix. It is isomorphic under the actions of their respective spaces, but they still live in separate spaces with separately defined actions. Likewise, the adjoint space of vectors is isomorphic to the space of row vectors but they are different spaces.

This fact seems like mumbo jumbo of mathematical rigor so most non mathematicians ignore it, but a 1x1 matrix is isomorphic to a scalar, while they are implemented very differently on the computer if you want performance, and this is why being rigorous matters here. If we don’t want to heap allocate each scalar and we want a vector times it’s adjoint to be a scalar, then we cannot drop the isomorphism relations to equalities.

4 Likes

Thanks for the reply and I have looked at the interesting video as well. I am happy that Julia has serious discussions on vectors and matrices. Normally when definitions are consistent within a language itself, then there should be no problems following consistent definitions.

The issue I got was from the bracket operation b=a[1:3,:], where data types are changed. My understanding was that b should be smaller than a or equal to a in dimensions, and this is not the case in Julia.

2 Likes

Surely it’s equal? If a is a Matrix, then b is also a Matrix?

The bracket operator could be used to access a section of data from a vector or a matrix. If a is a vector, then a(1:3), a(1:3,:), or a(1:3,:, : ) is also a vector in Matlab, because we couldn’t access something that is empty. Similar operations for a matrix. Why we do this is another question. The operation itself is valid without any warning or error. This is well documented in Matlab manual.

In Julia, I looked at the user manual and also searched online for the square bracket operator. The information I got is very limited. Clearly the square bracket operator has the function of accessing, but also extension of array dimensions if additional ',: ’ are placed inside the square bracket.

This is not a problem. However, a detailed user manual will be very helpful, from a user’s perspective.

Similar, if the vector and Nx1 matrix definitions could be detailed in the user manual, especially in the Linear Algebra section, that will be very helpful for beginners.

After all, a vector is normally considered as a Nx1 matrix in Linear Algebra. We could watch the MIT online open course, Linear Algebra, presented by well known Professor of mathematics Gilbert Strang (2. Elimination with Matrices. - YouTube). Prof. Strang stated that ‘We could even regard a column vector as a matrix with only one column (so n=1)’, and ‘All this is only common sense’ etc in the second chapter of his book ‘Introduction to Linear Algebra’.

If Julia defines a ‘flat’ vector for computational performance or any other reasons, that is perfectly ok. However, a well written user manual or document will be very helpful to avoid unnecessary user misunderstanding for Julia beginners. I don’t know if it is too much though, as Julia is clearly at the very early stage.

At the moment, I am still not clear where should we define a vector using zeros(n), or a matrix using zeros(n,1) for different applications.

I’m still not sure what you mean by this. Can you show an example?

The example has been given previously by ’ favba’ in this thread. I used to access some data from a, and the array dimension was changed. This operator also applies to matrices.

julia> a=zeros(5);

julia> typeof(a)
Array{Float64,1}

julia> b=a[1:2,:]
2×1 Array{Float64,2}:
 0.0
 0.0

julia> typeof(b)
Array{Float64,2}

Did you read through the relevant docs section? Specifically:

If all the indices are scalars, then the result X is a single element from the array A . Otherwise, X is an array with the same number of dimensions as the sum of the dimensionalities of all the indices.

Many thanks for the clear example. I didn’t find this, as I was looking for the operator.