logo

How to load a npy file in Julia 📂Julia

How to load a npy file in Julia

설명

1.png

This document outlines the process of calculating the Radon transform $\mathcal{R}f$ of a phantom $f$ in Python and saving the results as a *.npy file. To load this file in Julia, one can use the PyCall.jl package.

using PyCall
np = pyimport("numpy")

The above code is equivalent to executing import numpy as np in Python. This allows one to directly use the code written for numpy in Python to load $f$ and $\mathcal{R}f$.

f = np.load("f.npy")
Rf = np.load("Rf.npy")

To check if it has been correctly loaded, let’s visualize it using a heatmap.

p1 = heatmap(reverse(f, dims=1), color=:viridis)
p2 = heatmap(reverse(Rf, dims=1), color=:viridis)
plot(p1, p2, size=(728,250))

2.png

Environment

  • OS: Windows10
  • Version: Julia 1.6.2, PyCall 1.93.0