_linking to python with excel-python, and python matrix funct.pdf

Upload: apmapm

Post on 12-Oct-2015

138 views

Category:

Documents


2 download

TRANSCRIPT

  • Dividing shapes into layers Planxty and Litt le Musgrave

    Linking to Python with Excel-Python, and Pythonmatrix functionsPosted on May 22, 2014

    I have been experimenting for a few weeks with a new package linking Excel to Python, bythe name of ExcelPython. Here is what the author says about it:

    ExcelPython is a lightweight, easily distributable library for interfacingExcel and Python. It enables easy access to Python scripts from Excel VBA,allowing you to substitute VBA with Python for complex automation taskswhich would be facilitated by Pythons extensive standard library.

    The main points of differentiation from PyXll are:

    It is open source and free for all applications (GNU Lesser General Public License)All routines must be called via VBA (examples will be given in a later code, and mayalso be viewed in the download file)The number of data-types supported is much more restricted; excel variant arraysbeing transferred as Python lists of lists.Documentation is also lightweightBeing a non-commercial package, support will be limited, although to be fair, the authordoes seem to respond promptly to all queries on the discussion forum.Data is transferred to Python via COM, which allows data to be passed by reference.There are no facilities for setting up Excel Menus from Python code (so far as I know),and the Python docstrings are not transferred to the Excel function wizard.

    I found installation to be straightforward with my Anaconda Python setup. The onlyproblem I had was that if PyXll is installed, the add-in must be disabled before opening anyfile with ExcelPython code, otherwise an immediate crash results. To disable PyXll, go toFile-Options-Addins, click the Manage button, and unselect PyXll from the list of add-ins. It may easily be re-enabled from the same menu, when required.

    As an example of the use of Excel-Python, I have adapted the Matrixpyxll spreadsheet.The new file may be downloaded from MatrixXLpy.zip, including full open source code.

    The functions included in the new file are:

    CategoriesSelect Category

    RSS FeedRSS - PostsRSS - Comments

    Search NewtonExcelBach Search

    ArchivesSelect Month

    Top PostsUsing LINEST for non-linearcurve fittingDrawing in Excel 7 - Creatingdrawings from coordinatesCubic SplinesClearing excess formatsDaily Download 8: Drawing inExcelSection Properties of DefinedShapes - SpreadsheetDownloads by categoryThe DeserterArrays vs Collections vsDictionary Objects (andDictionary help)Writing an array to aworksheet range - correction

    Recent CommentsAlglib/Python spline onAlglib/Python linear andnon-lonline excel trainin onAlglib/Python splinefunctionsandre on Div iding shapesinto layedougaj4 on Div iding shapesinto layedougaj4 on 3DFrame Ver1.03 and Frame4 Veandre on Div iding shapesinto layedougaj4 on Alglib/Pythonlinear and non-lericremoreynolds onAlglib/Python linear andnon-lonline excel trainin onAlglib/Python linear andnon-l

    Newton Excel Bach, not (just) an Excel Blog

    Home About Newton Excel Bach Downloads Downloads by category Interactive Design Services Using Array Functions and UDFs

    Linking to Python with Excel-Python, and Python matrix functions | Newton Excel Bach, not (just) an Excel Blog 03/08/2014

    https://newtonexcelbach.wordpress.com/2014/05/22/linking-to-python-with-excel-python-and-python-matrix-functions/ 1 / 6

  • The matrix functions are used in a similar way to the built-in Excel matrix functions, andprovide identical results, but performance is very much better for large matrices.

    Eigenvalue and Eigenvector functions are provided, which have no equivalent in Excel.

    andre on Reinforced Concrete ULdougaj4 on Non linearregression 2; ALGEdson on 3DFrame Ver 1 .03and Frame4 Vedougaj4 on Tanh-SinhQuadrature V4.0Katto Ishimura on Tanh-SinhQuadrature V4.0Graeme Dennes on Tanh-SinhQuadrature V4.0

    Blogroll2toriaAdaptive ComplexityAJP Excel InformationAndrews Excel TipsArchesBacon BitsCode For Excel And OutlookBlogColin CapraniContextures BlogCosmic HorizonsDaily Dose of ExcelDick Moffat's Spreadsheet BlogExcel Blog HeadlinesExcel Do, Dynamic DoesExcel HeroExcel UnusualFastExcelGrumpy Old ProgrammerIn the DarkJan Karel PieterseJon Peltiers BlogLetters to NatureMath ProgrammingMethods in ExcelNot Only BridgesPearson Software ConsultingPlus MagazinePointy Haired DilbertRAD ExcelRon de BruinSimple SupportsSmurf on SpreadsheetsThe Happy PontistThe Math Less TraveledThe Numerical Methods GuyThe Spreadsheet PageVSTO, .NET and Excelxll add-in library

    Family LinksBare PicturesEMERGENCEFurniture DirectionsKerinne Jenkins

    Linking to Python with Excel-Python, and Python matrix functions | Newton Excel Bach, not (just) an Excel Blog 03/08/2014

    https://newtonexcelbach.wordpress.com/2014/05/22/linking-to-python-with-excel-python-and-python-matrix-functions/ 2 / 6

  • A variety of functions are provided to solve systems of simultaneous equations. Theexamples shown here on small data-sets provide identical results to use of the built-inMInverse and MMult functions, but provide much better performance, especially withlarge data sets.

    Functions linking to the PySparse library provide much better performance with largesparse systems, and also allow the solution of systems far larger than can beaccommodated by systems operating on the full matrix.

    Run times for 8 different functions are shown below with 4 different systems of equations:

    A small 10 x 10 system, solved 1000 times.A 1000 x 1000 system, solved onceA sparse 1000 x 1000 systemA sparse 10945 x 10945 system (sparse solvers only, this system would be much toolarge for the solvers operating on the full matrix)

    Linking to Python with Excel-Python, and Python matrix functions | Newton Excel Bach, not (just) an Excel Blog 03/08/2014

    https://newtonexcelbach.wordpress.com/2014/05/22/linking-to-python-with-excel-python-and-python-matrix-functions/ 3 / 6

  • For the small and medium sized dense systems the standard solvers were found to besignificantly faster than the sparse solvers, although it should be said that the code I usedfor setting up the sparse matrices was probably far from optimum. With the medium sizedsparse matrix the sparse solvers were significantly faster than the others, which hadalmost identical run times to the dense matrices of the same size. The iterative solver wasmarginally faster than the others with the medium sized sparse matrix, but with the largesparse matrix it was 5-10 times faster than the other sparse solvers.

    The data transfer time reported on the bottom row is the difference between the total runtime in VBA and the run time of the Python code. Note that this is a significant part of thetotal, especially for the larger dense matrix which required the transfer of a matrix of 1million doubles. To minimise this overhead the data transferred from Excel to Pythonshould be minimised, with the matrices being created in Python, using the functionsprovided in the PySparse library where possible.

    The next post in this series will look at the VBA code required to call the Python code, andalso differences required in the Python coding, compared with that required when Pyxll isused.

    Share this:

    Facebook LinkedIn 1 Tumblr Tw itter Google

    About these ads

    Related

    Python for VBA users - 1

    Evaluating text and Integration with Python and ALGLIB

    Download update - Python downloads

    Linking to Python with Excel-Python, and Python matrix functions | Newton Excel Bach, not (just) an Excel Blog 03/08/2014

    https://newtonexcelbach.wordpress.com/2014/05/22/linking-to-python-with-excel-python-and-python-matrix-functions/ 4 / 6

  • Dividing shapes into layers Planxty and Litt le Musgrave

    This entry was posted in Arrays, Excel, Finite Element Analysis, Frame Analysis, Link to Python, Maths, Newton,NumPy and SciPy, UDFs, VBA and tagged Excel, ExcelPython, Maths, Matrix Funct ions, Python, Simultaneousequat ions, sparse matrix solvers, UDF, VBA. Bookmark the permalink.

    5 Responses to Linking to Python with Excel-Python, andPython matrix functions

    Pingback: Python Matrix Functions with ExcelPython 2 | Newton Excel Bach, not (just) an Excel Blog

    bjoernstiel says:May 24, 2014 at 4:44 am

    Thanks for the interesting write-up. I can see the pros/cons of Excel-Python vsPyXLL. The former probably appeals more to those whove been doing VBAwhereas PyXLL feels more *natural* if you come from the traditional C API/XLLbackground. Theres also a new one Ive come across recently, called xlwings looks similar to Excel-Python.Definitely looking forward to the next post on this, would be interested to knowwhat the performance difference between PyXLL and Excel-Python (having theCOM overhead in mind). Thanks!

    Reply

    dougaj4 says:May 24, 2014 at 10:06 am

    Thanks bjoern. Xlwings certainly looks interesting!

    On the performance question, Im just playing with the code that wasmost recently posted in the forum on the ExcelPython site. Im getting ahuge reduction in the data transfer overhead time, but Im not sure whyat the moment! Ill certainly post something here when I have somenumbers that are reasonably representative.

    Reply

    ericremoreynolds says:June 5, 2014 at 6:16 pm

    xlwings does indeed look very interesting I remember comingacross it a while ago, before even starting on ExcelPython I think,but I cant remember why I decided to go ahead with my owninterface anyway.

    online excel training says:May 24, 2014 at 11:26 pm

    Interesting approachvery cool. Thanks for sharing.

    Reply

    Linking to Python with Excel-Python, and Python matrix functions | Newton Excel Bach, not (just) an Excel Blog 03/08/2014

    https://newtonexcelbach.wordpress.com/2014/05/22/linking-to-python-with-excel-python-and-python-matrix-functions/ 5 / 6

  • Newton Excel Bach, not (just) an Excel Blog

    Leave a Reply

    Enter your comment here...Enter your comment here...

    The Twenty Ten Theme. Blog at WordPress.com.

    FollowFollow

    Linking to Python with Excel-Python, and Python matrix functions | Newton Excel Bach, not (just) an Excel Blog 03/08/2014

    https://newtonexcelbach.wordpress.com/2014/05/22/linking-to-python-with-excel-python-and-python-matrix-functions/ 6 / 6

    CategoriesLinking to Python with Excel-Python, and Python matrixfunctionsRSS FeedSearch NewtonExcelBachArchivesTop PostsRecent CommentsBlogrollFamily LinksShare this:Related5 Responses to Linking to Python with Excel-Python, and Python matrixfunctionsLeave a Reply