Python matrix functions in Excel, using Pyxll

Newton Excel Bach, not (just) an Excel Blog

Following my previous Python post I have now successfully created a number of matrix arithmetic User Defined Functions (UDFs), using Python, SciPy and the PyXll add-in:

The spreadsheet and associated Python modules may be downloaded from

See the previous post for details of downloading and installing the necessary Python and PyXll files.

Writing the python modules proved to be very simple.  Two examples are shown below, and the rest are included in the download files:

@xl_func("numpy_array x: numpy_array")
def py_inv(x):
Return the inverse of a square matrix.
x: square matrix
return inv(x)
@xl_func("numpy_array x: numpy_array")
def py_trans(x):
Return the transpose of a matrix.
x: matrix
return transpose(x)

Note that there is no need to explicitly convert the spreadsheet range to a different data type, or re-size input and output arrays.  Also the comments under the function definition are automatically copied to the Excel function wizard, providing very…

View original post 73 more words