Macaulay2 » Documentation
Packages » Python » installNumPyMethods
next | previous | forward | backward | up | index | toc

installNumPyMethods -- install NumPy methods

Description

This function loads the NumPy module and installs several toPython and value(PythonObject) methods for converting back and forth between Macaulay2 matrices/vectors and NumPy arrays.

i1 : np = installNumPyMethods()

o1 = <module 'numpy' from '/usr/lib/python3/dist-packages/numpy/__init__.py'>

o1 : PythonObject of class module
i2 : A = toPython matrix {{1, 2}, {3, 4}}

o2 = [[1 2]
      [3 4]]

o2 : PythonObject of class numpy.ndarray
i3 : v = toPython vector {5, 6, 7}

o3 = [5 6 7]

o3 : PythonObject of class numpy.ndarray
i4 : value A

o4 = | 1 2 |
     | 3 4 |

              2       2
o4 : Matrix ZZ  <-- ZZ
i5 : value v

o5 = | 5 |
     | 6 |
     | 7 |

       3
o5 : ZZ

The output of the call to installNumPyMethods is a PythonObject referring to the module itself and can be used to call NumPy functions directly.

i6 : np@@arange(2, 9, 2)

o6 = [2 4 6 8]

o6 : PythonObject of class numpy.ndarray

For the programmer

The object installNumPyMethods is a function closure.


The source of this document is in Python/doc/numpy.m2:77:0.