using python to read a column vector from excel
<p>OK i think this must be a super simple thing to do, but i keep getting index error messages no matter how i try to format this.  my professor is making us multiply a 1X3 row vector by a 3x1 column vector, and i cant get python to read the column vector.  the row vector is from cells A1-C1, and the column vector is from cells A3-A5 in my excel spreadsheet.  I am using the right "format" for how he wants us to do it, (if i do something that works, but don't format it the way he likes i don't get credit.)  the row vector is reading properly in the variable explorer, but i am only getting a 2x2 column vector (with the first column being the 0th column and being all zeros, again how he wants it), I havent even gotten to the multiplication part of the code because i cant get python to read the column vector correctly. here is the code:</p>

<pre><code>import xlwings as xw
import numpy as np

filename = 'C:\\python\\homework4.xlsm'
wb=xw.Workbook(filename)

#initialize vectors
a = np.zeros((1+1,3+1))
b = np.zeros((3+1,1+1))

n=3

#Read a and b vectors from excel
for i in range(1,n+1):
    for j in range(1,n+1):
        a[i,j] = xw.Range((i,j)).value
    'end j'
    b[i,j] = xw.Range((i+2,j)).value
'end i'
</code></pre>

<p>Remember, Python use 0-based indexing and Excel use 1-based indexing. </p>

<p>This code will read out the vectors properly, and then you can check on numpy "scalar product" to produce the multiplication. You can also assign the whole vectors immediately without loop.</p>

<pre><code>import xlwings as xw
import numpy as np

filename = 'C:\\Temp\\Book2.xlsx'
wb=xw.Book(filename).sheets[0]

n=3

#initialize vectors
a = np.zeros((1,n))
b = np.zeros((n,1))

#Read a and b vectors from excel
for j in range(1,n+1):
  a[0, j-1] = wb.range((1, j)).value
  b[j-1, 0] = wb.range((j+3-1, 1)).value

#Without loop
a = wb.range((1, 1),(1, 3)).value
b = wb.range((3, 1),(5, 1)).value
</code></pre>

python excel vector