# Tips for moving from Julia to Numpy/Python?

**URL:** <https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702>\
**Category:** General Usage\
**Created:** [July 15, 2021, 4:46pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702 "2021-07-15T16:46:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 4:46pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/1 "2021-07-15T16:46:21Z")

</div>

I think I have to switch from using Julia to Python/Numpy. I know. I’m going the wrong way! Still, it’s become increasing apparent it’s the right thing to do.

I know Julia much better than Python/Numpy, but Julia isn’t supported by or is a huge PITA to get working in the tools we use at work.

Additionally the Python/Numpy ecosystem has improved quite a bit for my domain. [Geometric Computing with Python](https://geometryprocessing.github.io/geometric-computing-python/)  
[https://taichi.graphics/](https://taichi.graphics/)

I’ve seen this: [https://cheatsheets.quantecon.org/](https://cheatsheets.quantecon.org/)

Anyone have any tools/tips/resources for going from Julia to Python/Numpy? I have a lot of Julia code written.

Thanks.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 15, 2021, 4:47pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/2 "2021-07-15T16:47:24Z")

</div>

> [@Orbots](#):
>
> but Julia isn’t supported by or is a huge PITA to get working in the tools we use at work.

PyCall?

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 4:51pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/3 "2021-07-15T16:51:34Z")

</div>

I just said Julia isn’t supported. I can’t link to Julia.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 15, 2021, 4:58pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/4 "2021-07-15T16:58:00Z")

</div>

what do you mean by “link” to Julia?

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 4:59pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/5 "2021-07-15T16:59:49Z")

</div>

`dlopen()` or `gcc -ljulia`

---

<div class="post-metadata">

**Author:** ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)\
**Post date:** [July 15, 2021, 4:59pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/6 "2021-07-15T16:59:53Z")

</div>

> [@Orbots](#):
>
> [https://taichi.graphics/](https://taichi.graphics/)

related:

> <https://github.com/taichi-dev/taichi/issues/1642>
>
> \*\*Concisely describe the proposed feature\*\*
> A way to call Taichi kernels from J…ulia!
> 
> \*\*Describe the solution you'd like (if any)\*\*
> I'm aware of the following relevant issues:
> \* https://github.com/taichi-dev/taichi/issues/439
> \* https://github.com/taichi-dev/taichi/issues/1332
> \* https://github.com/taichi-dev/taichi/issues/920
> 
> With access to a \`.so\` file, this whole thing should be really quite straightforward using Julia's \[\`ccall\`\](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/) 🤞 From \[this comment\](https://github.com/taichi-dev/taichi/issues/439#issuecomment-656710151), it sounds as though all the ingredients are there already; they just need to be put together. I haven't been able to find any documentation about this however, eg. how do I go about compiling a kernel down into an \`.so\` file?
> 
> cc @archibate

> [@Orbots](#):
>
> Anyone have any tools/tips/resources for going from Julia to Python/Numpy? I have a lot of Julia code written.

see: [JuliaPy · GitHub](https://github.com/JuliaPy) projects

- using Conda ( Conda.jl )
- using pandas ( Pandas.jl )
- **calling your Julia code from Python → PyJulia ?**
  - [Usage — PyJulia 0.6.1 documentation](https://pyjulia.readthedocs.io/en/latest/usage.html#high-level-interface)
  - [GitHub - JuliaPy/pyjulia: python interface to julia](https://github.com/JuliaPy/pyjulia)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 15, 2021, 5:00pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/7 "2021-07-15T17:00:54Z")

</div>

More generally, probably you could explain better what you mean by “moving to”. You want to translate all your Julia code to Numpy? Or just learn numpy given a Julia experience?

Probably here you will get more tips on how to better integrate your Julia development workflow with the Python packages (or the C++ packages that are in that Python package).

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [July 15, 2021, 5:07pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/8 "2021-07-15T17:07:29Z")

</div>

We use numpy and Julia extensively, here are a few things we’ve found:

- PyJulia and PyCall are pretty great for interop, so you can keep using your existing code
- It’s really easy to pass arrays, Dicts, and scalar values like strings, numbers, etc. between the two. It’s harder, but doable, to pass more complex data structures. So try to keep any interfaces between the two limited to those data types.
- Julia has fast for loops, python/numpy doesn’t. So you’ll want to eliminate those as much as possible and lean heavily on vectorization
- Numpy doesn’t really have loop fusion, so you’ll need to be more careful monitoring memory usage

That’s about it. For the most part, translation is relatively straightforward.

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 5:07pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/9 "2021-07-15T17:07:31Z")

</div>

> [@lmiq](#):
>
> More generally, probably you could explain better what you mean by “moving to”. You want to translate all your Julia code to Numpy? Or just learn numpy given a Julia experience?

“Moving to” means, having Julia knowledge/code and probably a REPL open while prototyping but moving all that code/knowledge to python/numpy for the final product. Eventually not using Julia at all, and just writing python/numpy.

Best case scenario would be a source-to-source translator or julia-\>python compiler source. Next best is a good set of cheatsheets/tutorials/experiences on translating/rewriting julia to numpy The one I posted seems pretty good.

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 5:11pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/10 "2021-07-15T17:11:09Z")

</div>

> [@Satvik](#):
>
> lean heavily on vectorization

This seems to be the biggest difference between the numpy way of doing things and the Julia way. Although more recent Julia code is much more vectorized and closer to numpy in this way.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 15, 2021, 5:16pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/11 "2021-07-15T17:16:12Z")

</div>

> [@Orbots](#):
>
> Eventually not using Julia at all, and just writing python/numpy.

Translation should not be particularly difficult in general. It will be harder, depending on the code, to retain the performance, if the code is not easily vectorized. Perhaps you will finally have to learn some C, C++, or Numba, PyPy, to code some specific parts of the code that are more important for performance.

(as a side note, that particular package you mention above is just a front-end to a series of C++ libraries. A cool project could be to write that same front-end in Julia and have the best of both worlds).

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [July 15, 2021, 5:30pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/12 "2021-07-15T17:30:43Z")

</div>

@Orbots I don’t know if you’re still open to being convinced, but either way it would be helpful for us to know what is missing for you in Julia if you’re willing to talk about it.

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 5:32pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/13 "2021-07-15T17:32:18Z")

</div>

> [@lmiq](#):
>
> Perhaps you will finally have to learn some C, C++

You are assuming I don’t already? Strange.

> [@lmiq](#):
>
> write that same front-end in Julia

I already stated I can’t use Julia! That’s the whole point of this post. I’d _like_ to use julia, but it’s unreasonably difficult to do so.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [July 15, 2021, 5:34pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/14 "2021-07-15T17:34:14Z")

</div>

Btw there is a recent package announcement

> [@\[ANN\] Announcing NumPyArrays.jl](https://discourse.julialang.org/t/ann-announcing-numpyarrays-jl/64467):
>
> Synposis I am pleased to announce [NumPyArrays.jl](https://github.com/mkitti/NumPyArrays.jl) at version v0.1.1. Initial registration is in the general registry is in process. This package facilitates the conversion of certain Julia SubArrays, Base.ReinterpretedArrays, Base.ReshapedArray, and PermutedDimsArrays into NumPy arrays without copying if they have a mutable parent or ancestor. It also potentially allows other arrays where strides is applicable if they have a mutable parent or ancestor. PyCall.jl Currently, PyCall.jl will happ…

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 15, 2021, 5:38pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/15 "2021-07-15T17:38:10Z")

</div>

> [@Orbots](#):
>
> You are assuming I don’t already? Strange.

I was not assuming anything, it was just a remark about something to be considered in the migration process. Sorry if that felt differently in any way.

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [July 15, 2021, 5:39pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/16 "2021-07-15T17:39:26Z")

</div>

The nice thing about Julia is that it’s roughly equally fast whether you use vectorized or non-vectorized code. So if you’re porting Julia code to Python, one good option is to go through, find any for loops, and rewrite them using vectorization/broadcasting instead. Then you can almost copy & paste that code to python with minor modifications (I’ve done it!), you’ll just need to get rid of the dots for broadcasting.

---

<div class="post-metadata">

**Author:** ![Orbots](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orbots/32/3392_2.png) [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Post date:** [July 15, 2021, 5:46pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/17 "2021-07-15T17:46:35Z")

</div>

> [@jzr](#):
>
> what is missing for you in Julia

Fixes for these would be a start:

> <https://github.com/JuliaLang/julia/issues/32616>
>
> Summary of situation:
> built julia-1.2.0-rc2 from source for centos6 with gcc 6.…4.0 and -DGLIBCXX\_USE\_CXX11\_ABI=0
> dlopen an .so which embeds some simple julia code. “Lifted” into global namespace with dlopen(RTLD\_NOW | RTLD\_GLOBAL)
> from a maya plugin.
> 
> jl\_init() results in this assert:
> void\* jl\_init\_llvm(): Assertion \`jl\_TargetMachine && “Failed to select target machine -” " Is the LLVM backend for this CPU enabled?"’ failed.
> 
> Any ideas? A toy julia embedding works fine ( not loaded from maya )
> 
> versioninfo():
> Julia Version 1.2.0-rc2.0
> Platform Info:
> OS: Linux (x86\_64-pc-linux-gnu)
> CPU: Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)

> <https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/436>
>
> If you build julia 1.2 with statically linked LLVM ( need to patch first https:/…/github.com/JuliaLang/julia/issues/32665 ). Then BinaryBuilder will fail trying to build SpecialFunctions.jl

> <https://github.com/JuliaLang/PackageCompiler.jl/issues/462>
>
> Can't find a way to specify cflags for when gcc is called ( I specify a custom l…ocation for gcc with JULIA\_CC ).

> <https://github.com/JuliaLang/PackageCompiler.jl/pull/490>
>
> \* Similar to \`create\_app\`, this function facilitates the creation of
> C shared… library bundles using Julia.
> \* As with apps, it generates a directory tree with required shared
> libraries and artifacts.
> \* In contrast with apps, the julia system image is the main artifact
> generated, and its name should be set to the expected name of
> the library you're creating.
> \* One downside of this implementation is that any binaries linking
> to this shared library may need help finding it at runtime. The
> methods for doing so are system dependent.
> 
> Probably fixes #257, #350, #392.
> 
> Still needs documentation (at least). There is a bit of explanation in the function docs for \`create\_library\` that should probably be moved elsewhere.
> 
> Companion MR in https://github.com/simonbyrne/libcg/pull/18
> 
> Cc: @simonbyrne

After that, smaller binary size and better guarantees that JIT wont be called.

Some things to do with package system I don’t want to get into.

Even with all that, I need to maintain a more complicated build system to use julia, compared to python, which has 0 extra steps involved.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 15, 2021, 5:46pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/18 "2021-07-15T17:46:54Z")

</div>

@orbots, have you asked [here](https://discuss.python.org/)?

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [July 15, 2021, 6:11pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/19 "2021-07-15T18:11:07Z")

</div>

Make sure you have good test coverage before moving.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 15, 2021, 8:17pm UTC](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702/20 "2021-07-15T20:17:12Z")

</div>

> [@Orbots](#):
>
> Anyone have any tools/tips/resources for going from Julia to Python/Numpy? I have a lot of Julia code written.

If you do anything that benefits running Julia and Python in parallel to compare results, `IPython.jl` is invaluable.

[Next page](https://discourse.julialang.org/t/tips-for-moving-from-julia-to-numpy-python/64702.md?page=2)
