NumPy: Difference between revisions

From FreeCAD Documentation
(TOCright)
(Marked this version for translation)
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
<code>numpy</code> comes installed as a dependency of FreeCAD, therefore you can <code>import numpy as np</code> without having to first install it like in normal Python project environments.
<code>numpy</code> comes installed as a dependency of FreeCAD, therefore you can <code>import numpy as np</code> without having to first install it like in normal Python project environments.


== Convert Vector list between FreeCAD Python and NumPy ==
== Convert Vector list between FreeCAD Python and NumPy == <!--T:7-->


=== From Python to NumPy ===
=== From Python to NumPy === <!--T:8-->


</translate>
</translate>
Line 26: Line 26:
<translate>
<translate>


<!--T:9-->
Output is:
Output is:


Line 36: Line 37:
<translate>
<translate>


=== From NumPy to Python ===
=== From NumPy to Python === <!--T:10-->


</translate>
</translate>
Line 48: Line 49:
<translate>
<translate>


<!--T:11-->
Output is:
Output is:


Line 56: Line 58:
<translate>
<translate>


==FreeCAD Projects Using NumPy== <!--T:4-->
==FreeCAD projects using NumPy== <!--T:4-->


</translate>
</translate>
Line 63: Line 65:
<translate>
<translate>


==FreeCAD Forum Discussion== <!--T:5-->
==FreeCAD forum discussion== <!--T:5-->


<!--T:6-->
<!--T:6-->

Latest revision as of 09:45, 11 September 2022

Other languages:

Introduction

This page aims to document how to use NumPy with FreeCAD.

numpy comes installed as a dependency of FreeCAD, therefore you can import numpy as np without having to first install it like in normal Python project environments.

Convert Vector list between FreeCAD Python and NumPy

From Python to NumPy

import FreeCAD as App
import numpy as np

vector_list = [App.Vector(1, 0, 0), App.Vector(1, 2, 3), App.Vector(0, 3, 0)]
numpy_array = np.asarray(vector_list)
print(numpy_array)

Output is:

[[ 1.  0.  0.]
 [ 1.  2.  3.]
 [ 0.  3.  0.]]

From NumPy to Python

import FreeCAD as App
import numpy as np

cad_list = [App.Vector(itm) for itm in numpy_array]
print(cad_list)

Output is:

[Vector (1.0, 0.0, 0.0), Vector (1.0, 2.0, 3.0), Vector (0.0, 3.0, 0.0)]

FreeCAD projects using NumPy

FreeCAD forum discussion