用法一
readdlm(source, delim::AbstractChar, T::Type, eol::AbstractChar; header=false, skipstart=0, skipblanks=true, use_mmap, quotes=true, dims, comments=false, comment_char='#')
從源中讀取矩陣,其中每一行(由 eol
分隔)給出一行,元素由給定的分隔符分隔。源可以是文本文件、流或字節數組。可以通過將映射段的字節數組表示作為源來使用內存映射文件。
如果T
是數字類型,則結果是該類型的數組,任何非數字元素都為浮點類型的NaN
,或為零。 T
的其他有用值包括 String
、 AbstractString
和 Any
。
如果 header
是 true
,則第一行數據將作為標題讀取,並返回元組 (data_cells, header_cells)
而不僅僅是 data_cells
。
指定skipstart
將忽略輸入中相應數量的初始行。
如果 skipblanks
是 true
,則輸入中的空白行將被忽略。
如果 use_mmap
是 true
,則 source
指定的文件是內存映射的,如果文件很大,則可能會加快速度。默認值為 false'. On a Windows filesystem,
use_mmap should not be set to
true`,除非文件隻被讀取一次並且也不會被寫入。存在一些邊情況,其中操作係統為Unix-like,但文件係統為Windows-like。
如果 quotes
是 true
,則包含在 double-quote (") 字符中的列允許包含新行和列分隔符。引用字段中的 Double-quote 字符必須使用另一個 double-quote 進行轉義。指定 dims
作為預期行和列的元組(包括標題,如果有的話)可能會加快讀取大文件。如果 comments
是 true
,則任何行中以 comment_char
開頭的行和 comment_char
之後的文本都將被忽略.
例子
julia> using DelimitedFiles
julia> x = [1; 2; 3; 4];
julia> y = [5; 6; 7; 8];
julia> open("delim_file.txt", "w") do io
writedlm(io, [x y])
end
julia> readdlm("delim_file.txt", '\t', Int, '\n')
4×2 Matrix{Int64}:
1 5
2 6
3 7
4 8
julia> rm("delim_file.txt")
用法二
readdlm(source, delim::AbstractChar, T::Type; options...)
行尾分隔符被視為 \n
。
例子
julia> using DelimitedFiles
julia> x = [1; 2; 3; 4];
julia> y = [1.1; 2.2; 3.3; 4.4];
julia> open("delim_file.txt", "w") do io
writedlm(io, [x y], ',')
end;
julia> readdlm("delim_file.txt", ',', Float64)
4×2 Matrix{Float64}:
1.0 1.1
2.0 2.2
3.0 3.3
4.0 4.4
julia> rm("delim_file.txt")
用法三
readdlm(source, delim::AbstractChar; options...)
行尾分隔符被視為 \n
。如果所有數據都是數字,則結果將是一個數字數組。如果某些元素無法解析為數字,則返回一個由數字和字符串組成的異構數組。
例子
julia> using DelimitedFiles
julia> x = [1; 2; 3; 4];
julia> y = [1.1; 2.2; 3.3; 4.4];
julia> open("delim_file.txt", "w") do io
writedlm(io, [x y], ',')
end;
julia> readdlm("delim_file.txt", ',')
4×2 Matrix{Float64}:
1.0 1.1
2.0 2.2
3.0 3.3
4.0 4.4
julia> z = ["a"; "b"; "c"; "d"];
julia> open("delim_file.txt", "w") do io
writedlm(io, [x z], ',')
end;
julia> readdlm("delim_file.txt", ',')
4×2 Matrix{Any}:
1 "a"
2 "b"
3 "c"
4 "d"
julia> rm("delim_file.txt")
用法四
readdlm(source, T::Type; options...)
假定列由一個或多個空格分隔。行尾分隔符被視為 \n
。
例子
julia> using DelimitedFiles
julia> x = [1; 2; 3; 4];
julia> y = [5; 6; 7; 8];
julia> open("delim_file.txt", "w") do io
writedlm(io, [x y])
end;
julia> readdlm("delim_file.txt", Int64)
4×2 Matrix{Int64}:
1 5
2 6
3 7
4 8
julia> readdlm("delim_file.txt", Float64)
4×2 Matrix{Float64}:
1.0 5.0
2.0 6.0
3.0 7.0
4.0 8.0
julia> rm("delim_file.txt")
用法五
readdlm(source; options...)
假定列由一個或多個空格分隔。行尾分隔符被視為 \n
。如果所有數據都是數字,則結果將是一個數字數組。如果某些元素無法解析為數字,則返回一個由數字和字符串組成的異構數組。
例子
julia> using DelimitedFiles
julia> x = [1; 2; 3; 4];
julia> y = ["a"; "b"; "c"; "d"];
julia> open("delim_file.txt", "w") do io
writedlm(io, [x y])
end;
julia> readdlm("delim_file.txt")
4×2 Matrix{Any}:
1 "a"
2 "b"
3 "c"
4 "d"
julia> rm("delim_file.txt")
相關用法
- Julia DelimitedFiles.writedlm用法及代碼示例
- Julia Distributed.procs方法用法及代碼示例
- Julia Dims()用法及代碼示例
- Julia Dates.week用法及代碼示例
- Julia Dates.CompoundPeriod方法用法及代碼示例
- Julia Distributed.remotecall_fetch方法用法及代碼示例
- Julia Dict用法及代碼示例
- Julia Distributed.@spawnat用法及代碼示例
- Julia Distributed.remotecall方法用法及代碼示例
- Julia Dates.monthname用法及代碼示例
- Julia Dates.Time方法用法及代碼示例
- Julia Distributed.default_worker_pool用法及代碼示例
- Julia Dates.firstdayofmonth用法及代碼示例
- Julia Dates.lastdayofmonth用法及代碼示例
- Julia Distributed.@fetch用法及代碼示例
- Julia Distributed.myid用法及代碼示例
- Julia Dates.lastdayofweek用法及代碼示例
- Julia Distributed.nprocs用法及代碼示例
- Julia Distributed.@fetchfrom用法及代碼示例
- Julia Distributed.remotecall_wait方法用法及代碼示例
- Julia Dates.lastdayofyear用法及代碼示例
- Julia Docs.@html_str用法及代碼示例
- Julia Dates.daysinyear用法及代碼示例
- Julia Distributed.workers用法及代碼示例
- Julia Dates.dayofweekofmonth用法及代碼示例
注:本文由純淨天空篩選整理自julialang.org 大神的英文原創作品 DelimitedFiles.readdlm — Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。