NumPy

From FreeCAD Documentation
Revision as of 11:16, 9 September 2022 by Catman (talk | contribs) (adding example from thread)
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 AppVector between FreeCAD Python and NumPy

  • From Python to NumPy
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 numpy as np

CAD_list = []
for i in numpy_array:
    CAD_list.append(App.Vector(i))
 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