NPZ.jl
NPZ.npzread
— Methodnpzread(filename::AbstractString, [vars])
Read a variable or a collection of variables from filename
. The input needs to be either an npy
or an npz
file. The optional argument vars
is used only for npz
files. If it is specified, only the matching variables are read in from the file.
Zero-dimensional arrays are stripped while being read in, and the values that they contain are returned. This is a notable difference from numpy, where numerical values are written out and read back in as zero-dimensional arrays.
Examples
julia> npzwrite("temp.npz", x = ones(3), y = 3)
julia> npzread("temp.npz") # Reads all variables
Dict{String,Any} with 2 entries:
"x" => [1.0, 1.0, 1.0]
"y" => 3
julia> npzread("temp.npz", ["x"]) # Reads only "x"
Dict{String,Array{Float64,1}} with 1 entry:
"x" => [1.0, 1.0, 1.0]
NPZ.npzwrite
— Methodnpzwrite(filename::AbstractString, x)
Write the variable x
to the npy
file filename
. Unlike numpy
, the extension .npy
is not appened to filename
.
Any existing file with the same name will be overwritten.
Examples
julia> npzwrite("abc.npy", zeros(3))
julia> npzread("abc.npy")
3-element Array{Float64,1}:
0.0
0.0
0.0
NPZ.npzwrite
— Methodnpzwrite(filename::AbstractString, vars::Dict{<:AbstractString})
npzwrite(filename::AbstractString, args...; kwargs...)
In the first form, write the variables in vars
to an npz
file named filename
.
In the second form, collect the variables in args
and kwargs
and write them all to filename
. The variables in args
are saved with names arr_0
, arr_1
and so on, whereas the ones in kwargs
are saved with the specified names.
Unlike numpy
, the extension .npz
is not appened to filename
.
Any existing file with the same name will be overwritten.
Examples
julia> npzwrite("temp.npz", Dict("x" => ones(3), "y" => 3))
julia> npzread("temp.npz")
Dict{String,Any} with 2 entries:
"x" => [1.0, 1.0, 1.0]
"y" => 3
julia> npzwrite("temp.npz", ones(2,2), x = ones(3), y = 3)
julia> npzread("temp.npz")
Dict{String,Any} with 3 entries:
"arr_0" => [1.0 1.0; 1.0 1.0]
"x" => [1.0, 1.0, 1.0]
"y" => 3
NPZ.readheader
— Methodreadheader(filename, [vars...])
Return a header or a collection of headers corresponding to each variable contained in filename
. The header contains information about the eltype
and size
of the array that may be extracted using the corresponding accessor functions.