This means in Julia [0] != 0. Although I can understand this rule, I feel it inconvenient to use. Do I have to build awareness of this kind and to code carefully when using Julia, or is there any workaround to make it more convenient?
Unlike, R or Matlab, Julia does not identify vectors and scalars as they are fundamentally different data structures, e.g., vectors are mutable, but scalars not. Thus, you need to take a bit more care about that.
If you happen to know that your vector/matrix is actually a singleton, you can use only to extract the value:
julia> only(2 .- [1 1] * [1; 1]) == 0
true
The behaviour of R can be replicated via broadcasting:
Not that dot([1, 2], [3, 4]) and [1, 2]' * [3, 4] are essentially equivalent in Julia, because [1, 2]' acts like a covector, as discussed in Transposes vs 1-row matrices
Thank you for making it more complete and accurate, although this kind of syntax makes me feel somewhat confused that I couldn’t find a consistent way to understand Julia’s syntax rules regarding vectors and matrices.
Using double semicolons for the horizontal concatenation, on the other hand, performs any vertical concatenations before horizontally concatenating the result. […] Just as ; and ;; concatenate in the first and second dimension, using more semicolons extends this same general scheme. The number of semicolons in the separator specifies the particular dimension, so ;;; concatenates in the third dimension, ;;;; in the 4th, and so on. Fewer semicolons take precedence, so the lower dimensions are generally concatenated first.
(It’s not very common to need to define a 1-column matrix literal expression like [1; 2;;], and the syntax for this was only added to Julia fairly recently. I don’t think I’ve ever used it in practice myself. You can safely ignore the ;;… corner of the language if you find it confusing.)
There is no such thing as a row-vector in julia. When you transpose or form the adjoint of a Vector you get a 2-dimensional structure, essentially a one-row matrix.
julia> a = rand(4)
4-element Vector{Float64}:
0.2034574270239713
0.7019936882200452
0.9387129254650988
0.5892713898810321
julia> b = a'
1×4 adjoint(::Vector{Float64}) with eltype Float64:
0.203457 0.701994 0.938713 0.589271
julia> size(a)
(4,)
julia> size(b)
(1, 4)
But, I agree that it’s a bit confusing, because the adjoint acts as a co-vector, not as a 1x4 matrix when multiplying with a vector.
BTW, asking questions here is completely fine, but TBH I think using the Manual more would be an efficiency win for you, given that I think all your questions are answered in the Manual.
BTW, in case you’re interested, the docs for <: are better in the in-development version of Julia than for the released version, here’s the link: <:
Thank you for your advice! I completely agree and acknowledge that I need to improve my efficiency in accurately locating my issues in the documentation. It is undeniable that asking questions here has provided me with a lot of friendly help (including yours), which has increased my familiarity with the documentation and helped me learn things beyond the documentation. For example, I learned from you that
This information has been very helpful.
I apologize for the presumption, but I cannot agree with your viewpoint that seems too absolute. As a novice in the Julia language, although some of my questions may appear elementary to you, the fact is that through my interactions and discussions with the community here, as well as my own exploration, I have discovered several (potential) bugs in Julia itself or in Julia packages (perhaps more than five recently?) and raised some issues on GitHub. Don’t you think this is beneficial for Julia, its developers, and its users? If your answer is negative, I will try to minimize my exploration and inquiries regarding such issues.
Please continue asking questions, they are absolutely welcome. Each answer here (even if only pointing to the proper manual page) helps other users to find answers to similar questions.