3 ms·
I mean, I don't know if this is bad, but I do find the behavior to be surprising: julia> d = [1 2; 3 4] julia> d 2×2 Matrix{Int64}: 1 2
by UncleOxidant 5y ago
I mean, I don't know if this is bad, but I do find the behavior to be surprising:
julia> d = [1 2; 3 4]
julia> d
2×2 Matrix{Int64}:
1 2
3 4
julia> @show( d[1], d[2], d[3], d[4] )
d[1] = 1
d[2] = 3
d[3] = 2
d[4] = 4
I guess I would have expected something like:
d[1] = 1 2
d[2] = 3 4
d[3] -> array index out of bounds error
but looks like you have to do:
julia> d[1,:]
2-element Vector{Int64}:
1
2
- eigenspace 5y agoThis is known as Column major order. https://en.wikipedia.org/wiki/Row-_and_column-major_order#Programming_languages_and_libraries https://en.wikipedia.org/wiki/Row-_and_column-major_order#Pr...
- klaff 5y agohttps://docs.julialang.org/en/v1/manual/arrays/#Linear-indexing https://docs.julialang.org/en/v1/manual/arrays/#Linear-index...
- UncleOxidant 5y agoOk... I read that. I have to say it's very not intuitive. I like Julia overall, but this is an area where I scratch my head and say "Hmmm... why would they do that?" (performance, I'd guess, but it's not very user friendly). Is there a set of guidelines for translating Python/numpy code to Julia because indexing in Python/numpy works a lot differently (and seems more intuitive).
- klaff 5y agoYou've probably found this already: https://docs.julialang.org/en/v1/manual/noteworthy-differences/#Noteworthy-differences-from-Python https://docs.julialang.org/en/v1/manual/noteworthy-differenc... That's the only "official" python-julia resource I know of although I bet there are some blogs about the process.
- klaff 5y agoI will also say, a number of times I've thought something like "why would they do that?", and some months later (I'm kinda slow) I would realize that it now makes sense.