Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Inverse of a Matrix Macro

kevin_jaiwant
5 - Atom

Is there an easy way to mimic a matrix and then take the INVERSE of that matrix? Does anyone have a macro for this or could help create?

 

We have a Matrix multiplier macro, but require one for taking the inverse of a matrix. Thanks in advance!

1 REPLY 1
danilang
19 - Altair
19 - Altair

Hi @kevin_jaiwant 

 

Finding the inverse of matrix is a complex algorithm that would be very time consuming to reproduce in Alteryx probably involving nested macros.  In light of the difficulty involved, I'm going to do what you did and ask someone else to help.  Python...I choose you.  The numpy library in python already has an matrix inv function so I'm going use this in the python tool.   

danilang_1-1667053089505.png

 

The code is quite simple.  The meat of the function is inv = np.linalg.inv(arr).  The other rows read from alteryx, convert to numpy.array format, convert the result from array to dataframe and write back.  

 

If you convert the text input to a Macro Input and the Browse to a Macro Output, you'll be able to drop the resulting macro into any workflow and no one will even know that you're using python.  

 

Note.  Not all matrices have an inverse so may want to check what is returned if try one of those.

 

Dan

 

  

Labels