Transpose of an array of Strings

I thought that collect(1:5) returned [1,2,3,4,5], which is different.
1:5 is an iterator, so I do not see how == is possible. If you are, correct, I indeed
Have a very serious misunderstanding.

Gordon

1:5 is just a clever way of representing [1, 2, 3, 4, 5] without wasting memory. The point is that their behavior should be exactly the same.

This is the purpose of the AbstractVector type family.

This post might help clarify things: https://stackoverflow.com/a/38638838/12486544. It’s a bit out of date (I don’t think === is still an alias for is) but helps explain what == means.

I do not want to sound rude but this is something you can check in half a minute in the REPL, there is no reason to write a comment questioning it and create more noise instead of checking it first.

julia> 1:5 == [1, 2, 3, 4, 5]
true

julia> typeof(1:5)
UnitRange{Int64}

julia> typeof([1, 2, 3, 4, 5])
Array{Int64,1}

julia> 1 == 1.0
true

Objects of different types can be considered equal. And an iterator/range is semantically a collection, even if it is represented by a fixed size object.

1 Like

I understand your point. However, notemthat you cannot domthe following g:

a= 1:5
b = a[2]

However,

a= [1,2,3,4,5]
b= a[2]

Is allowed. Therefore, their behavior is not the same. Would you suggest that they should be the same?

I would submitmthat 1:5 has the behavior of an iterator, which defines the equivalent of the next operator. Collect acts on 1:5 to return a vector. I do not know whether collect acts on more general iterators, go en that in principles, iterators can have infinite length.

Thanks, and I apologize. I do not have a computer at my disposal. I am working from an iPad. I’m will drop it.

I do not want to sound rude but this is something you can check in half a minute in the REPL, there is no reason to write a comment questioning it and create more noise instead of checking it first.

So I domhave a question: why not allow (1:5)[5] as an operation?

julia> (6:10)[3]
8

It is allowed.

1 Like

Yes, you can. This works perfectly well. The thing you cannot do is mutate a, it’s an Immutable array. Ranges are vectors. Just try

(1:5) isa AbstractVector 
2 Likes

Maybe this can help you: https://repl.it/languages/julia

1 Like

:man_facepalming:

2 Likes

The solution:

reshape(b,1,: )

permutedims is probably easier

1 Like