Julia eltype

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mifangdebaise/article/details/84917552

eltype 自己理解就是 每个元素的类型

julia> 1f0
1.0f0

julia> typeof(1f0)
Float32

julia> fill(1f0, (2,2))
2×2 Array{Float32,2}:
 1.0  1.0
 1.0  1.0
 
julia> eltype(fill(1f0, (2,2)))
Float32
help?> eltype
search: eltype fieldtype

  eltype(type)

  Determine the type of the elements generated by iterating a collection of
  the given type. For dictionary types, this will be a Pair{KeyType,ValType}.
  The definition eltype(x) = eltype(typeof(x)) is provided for convenience so
  that instances can be passed instead of types. However the form that accepts
  a type argument should be defined for new types.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> eltype(fill(1f0, (2,2)))
  Float32
  
  julia> eltype(fill(0x1, (2,2)))
  UInt8

猜你喜欢

转载自blog.csdn.net/mifangdebaise/article/details/84917552