How to get the typeof properties in Julia
a = reshape(1:15,3,5)
b = typeof(a)
Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}
How can I get 'Int64' property of 'b'?
'2' is the number of dimensions. right. How to get that info from 'b'?
How to get the typeof properties in Julia
a = reshape(1:15,3,5)
b = typeof(a)
Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}
How can I get 'Int64' property of 'b'?
'2' is the number of dimensions. right. How to get that info from 'b'?
there is the function ndims to get the number of dimensions of an array, and eltype for the return type:
julia> a = reshape(1:15,3,5);
julia> ndims(a)
2
julia> eltype(a)
Int64
more generally to get type parameters, you can use multiple dispatch:
julia> my_eltype(x::AbstractArray{T}) where T = T
my_eltype (generic function with 1 method)
julia> my_eltype(a)
Int64
julia> my_ndims(x::AbstractArray{T,N}) where {T,N} = N
my_ndims (generic function with 1 method)
julia> my_ndims(a)
2