title: Modifying a matrix to include various data features
body: <p>I have the following correlations:</p>
  <pre><code>    a     b     c
  a   1     0.9   0.8
  b   0.9   1     0.7
  c   0.8   0.7   1
  </code></pre>
  <p>and the following vectors:</p>
  <pre><code>col1    col2    col3
  c1      a       5
  c2      a       -6
  c1      b       10
  c2      b       -15
  c1      c       24
  c2      c       -30
  </code></pre>
  <p>The aim is to multiply the 'col3' vector vs the correlation matrix matching elements per 'col2', all whilst bearing in mind that an extra weight of 0.7 is to be added when 'col1' differs:</p>
  <p><a href="https://i.stack.imgur.com/QI0Iy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QI0Iy.png" alt="enter image description here" /></a></p>
  <p>blue Corr(c1a,c1a): 25 = 5 * 5 * 1</p>
  <p>green Corr(c1a,c2a): -21 = 5 * -6 * 1 * .7</p>
  <p>yellow Corr(c1a,c1b): 45 = 5 * 10 * .9</p>
  <p>red Corr(c1a,c2b): -47.25 = 5 * -15 * .9 * .7</p>
  <p>'col1' won't always differ (there are cases when it will always be 'c1' so the extra 0.7 weight won't be needed and the problem will just be straight matrix multiplication)</p>
  <p>Is there a more pythonic way to express the above?</p>
  <p>My initial idea was to expand the correlation matrix as follows:</p>
  <p><a href="https://i.stack.imgur.com/IwAkE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IwAkE.png" alt="enter image description here" /></a></p>
  <p>blue: 1</p>
  <p>green: 0.7 = 1 * 0.7</p>
  <p>yellow: 0.9</p>
  <p>red: 0.63 = 0.9 * 0.7</p>
  <p>and then do the aforementioned operation via einsum or tensordot with the vectors. (But I'm struggling setting this up dynamically for other vector scenarios)
  Perhaps there is a better way to approach this.
  Any other suggestions would be great!</p>
  <p><strong>SET UP:</strong></p>
  <pre><code>import pandas as pd
  
  corr = pd.DataFrame({'a':[1,.9,.8],
                       'b':[.9,1,.7],
                       'c':[.8,.7,1]},
                       index = ['a','b','c'])
  
  inputs = pd.DataFrame({'col1':['c1','c2','c1','c2','c1','c2'],
                         'col2':['a','a','b','b','c','c'],
                         'col3':[5,-6,10,-15,24,-30]})
  </code></pre>