NumPy

From FreeCAD Documentation
This page is a translated version of the page NumPy and the translation is 100% complete.
Other languages:

Introduzione

Questa pagina ha lo scopo di documentare come utilizzare numpy con FreeCAD.

numpy viene installato come dipendenza di FreeCAD, quindi è possibile fare import numpy as np senza doverlo prima installare come nei normali ambienti di sviluppo di Python.

Convertire una lista di vettori tra FreeCAD Python e NumPy

Da Python a 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)

L'output è:

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

Da NumPy a Python

import FreeCAD as App
import numpy as np

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

L'output è:

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

Progetti FreeCAD che utilizzano NumPy

Discussione nel forum di FreeCAD