# How to save an matrix to use in a separate script

**URL:** <https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 23, 2023, 3:49pm UTC](https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518 "2023-03-23T15:49:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_tud](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dan\_tud](https://discourse.julialang.org/u/dan_tud)\
**Post date:** [March 23, 2023, 3:49pm UTC](https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518/1 "2023-03-23T15:49:57Z")

</div>

Hi All,

Apologies if this has been asked, however, I haven’t been able to find a simple answer. I have a matrix of solutions which I would like to save and then load into another script for plotting and some analysis. My solutions are the output of Method of Lines package, if this helps. I’m sure there is something simple, in Python I would use pickle, but not sure what the Julia equivalent is?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [March 23, 2023, 3:55pm UTC](https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518/2 "2023-03-23T15:55:01Z")

</div>

I would recommend `BSON`:

```julia
using Pkg
Pkg.add("BSON")
using BSON: @save, @load

@save "path/to/file.bson" your_data

```

Then to load from the other file:

```julia
using BSON: @save, @load

@load "path/to/file.bson" your_data

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 23, 2023, 4:00pm UTC](https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518/3 "2023-03-23T16:00:56Z")

</div>

> [@dan\_tud](#):
>
> I’m sure there is something simple, in Python I would use pickle, but not sure what the Julia equivalent is?

There are lots of file formats. You can use text formats like [CSV](https://csv.juliadata.org/stable/), binary formats like the above-mentioned BSON or [HDF5](https://juliaio.github.io/HDF5.jl/stable/), or more Julia-specific formats like [JLD](https://github.com/JuliaIO/JLD.jl); see the links for how to read and write them in Julia. Probably JLD or [JLD2](https://github.com/JuliaIO/JLD2.jl) is a good choice for interchanging data between Julia scripts; if you want to exchange data with other software I would generally use CSV or HDF5.

---

<div class="post-metadata">

**Author:** ![dan\_tud](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dan\_tud](https://discourse.julialang.org/u/dan_tud)\
**Post date:** [March 23, 2023, 4:02pm UTC](https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518/4 "2023-03-23T16:02:57Z")

</div>

Thanks both, I think JLD is what I was looking for!

---

<div class="post-metadata">

**Author:** ![fer2tdt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fer2tdt/32/47427_2.png) [@fer2tdt](https://discourse.julialang.org/u/fer2tdt)\
**Post date:** [June 16, 2023, 7:19am UTC](https://discourse.julialang.org/t/how-to-save-an-matrix-to-use-in-a-separate-script/96518/5 "2023-06-16T07:19:35Z")

</div>

Hi, the next code using JLD2 could be usesfull:

 ![Screenshot from 2023-06-16 09-12-18](https://global.discourse-cdn.com/julialang/original/3X/2/6/2666b58e45a7447123a02ede7ee57d058f27f22a.png)

```julia
using Pkg
using JLD2
function save_Array_JLD2(nameIN::Array{}, prefixfile::String)
        # Save nameIN object into prefixfile.jld2
        namefile=prefixfile*".jld2"
        save_object(namefile, nameIN)
    end
export save_DF_JLD2
#
function load_JLD2(prefixfile::String)
        # Load in memory the object from prefixfile.jld2
        namefile=prefixfile*".jld2"
        return load_object(namefile)
end

```
