NumPy: Difference between revisions
Renatorivo (talk | contribs) No edit summary |
(Marked this version for translation) |
||
(13 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
<languages/> |
||
{{TOCright}} |
|||
<translate> |
<translate> |
||
==Introduction== |
==Introduction== <!--T:1--> |
||
<!--T:2--> |
|||
This page aims to document how to use [https://numpy.org/ NumPy] with FreeCAD. |
This page aims to document how to use [https://numpy.org/ NumPy] with FreeCAD. |
||
<!--T:3--> |
|||
<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. |
||
==FreeCAD |
== Convert Vector list between FreeCAD Python and NumPy == <!--T:7--> |
||
=== From Python to NumPy === <!--T:8--> |
|||
⚫ | |||
{{Code|code= |
|||
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) |
|||
}} |
|||
<translate> |
|||
<!--T:9--> |
|||
Output is: |
|||
</translate> |
|||
{{Code|lang=text|code= |
|||
[[ 1. 0. 0.] |
|||
[ 1. 2. 3.] |
|||
[ 0. 3. 0.]] |
|||
}} |
|||
<translate> |
|||
=== From NumPy to Python === <!--T:10--> |
|||
</translate> |
|||
{{Code|code= |
|||
import FreeCAD as App |
|||
import numpy as np |
|||
cad_list = [App.Vector(itm) for itm in numpy_array] |
|||
print(cad_list) |
|||
}} |
|||
<translate> |
|||
<!--T:11--> |
|||
Output is: |
|||
</translate> |
|||
{{Code|lang=text|code= |
|||
[Vector (1.0, 0.0, 0.0), Vector (1.0, 2.0, 3.0), Vector (0.0, 3.0, 0.0)] |
|||
}} |
|||
<translate> |
|||
==FreeCAD projects using NumPy== <!--T:4--> |
|||
</translate> |
</translate> |
||
* https://github.com/looooo/freecad.gears/blob/master/setup.py#L13 |
* https://github.com/looooo/freecad.gears/blob/master/setup.py#L13 |
||
* https://github.com/booya-at/OpenGlider/blob/develop/setup.py#L77 |
* https://github.com/booya-at/OpenGlider/blob/develop/setup.py#L77 |
||
<translate> |
<translate> |
||
==FreeCAD Forum Discussion== |
|||
==FreeCAD forum discussion== <!--T:5--> |
|||
⚫ | |||
<!--T:6--> |
|||
* [https://forum.freecadweb.org/viewtopic.php?f=22&t=47529 Any numpy experts?] |
* [https://forum.freecadweb.org/viewtopic.php?f=22&t=47529 Any numpy experts?] |
||
</translate> |
|||
[[Category:3rd Party{{#translation:}}]] |
|||
{{clear}} |
Latest revision as of 09:45, 11 September 2022
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
- https://github.com/looooo/freecad.gears/blob/master/setup.py#L13
- https://github.com/booya-at/OpenGlider/blob/develop/setup.py#L77