I am wondering, without using for loops, how to extract a 2 x 2 matrix consisting of the 1st entries of this matrix of matrices, i.e.,
2x2 Matrix{Int64}
1 3
5 7
Also, a matrix of its 2nd entries, i.e.,
2x2 Matrix{Int64}
2 4
6 8
Is there a nice and quick way to do this? (Of course, what I really want is to do the same for large matrices of matrices or vectors, but this 2x2 example sufficiently describe my intention.)
Thanks a lot in advance!
Note that in Julia vocab, [1 2] is not a vector but a 1x2 matrix. If you don’t have a specific reason to store your data like this, using [1, 2] is more Julian.
BTW, what I really wanted to do is to generate a vector field on a 2D plane, say, the unit square, and draw that vector field using quiver plot in Plots.jl. So, here is an example on a very small grid.
julia> using LazyGrids # this allows to generate meshes like in MATLAB
julia> X, Y = ndgrid((collect(0:1), collect(0:1));
julia> X
2×2 LazyGrids.GridAV{Int64, 1, 2}:
0 0
1 1
julia> Y
2×2 LazyGrids.GridAV{Int64, 2, 2}:
0 1
0 1
julia> f(x,y) = [0.0 1.0; 1.0 0.0] * [x; y]; # Just a simple example of generating a vector at (x,y).
julia> A = f.(X,Y) # pointwise evaluation of f on the mesh
2×2 Matrix{Vector{Float64}}:
[0.0, 0.0] [1.0, 0.0]
[0.0, 1.0] [1.0, 1.0]
Then, in order to use quiver plot, I need to extract the first components and the second components: