title: Does np.dot automatically transpose vectors?
body: <p>I am trying to calculate the first and second order moments for a portfolio of stocks (i.e. expected return and standard deviation). </p>
  
  <pre><code>expected_returns_annual
  Out[54]: 
             ticker
  adj_close  CNP       0.091859
             F        -0.007358
             GE        0.095399
             TSLA      0.204873
             WMT      -0.000943
  dtype: float64
  
  type(expected_returns_annual)
  Out[55]: pandas.core.series.Series
  
  
  
  weights = np.random.random(num_assets)
  weights /= np.sum(weights)
  returns = np.dot(expected_returns_annual, weights)
  </code></pre>
  
  <p>So normally the expected return is calculated by</p>
  
  <p>(x1,...,xn' * (R1,...,Rn)</p>
  
  <p>with x1,...,xn are weights with a constraint that all the weights have to sum up to 1 and ' means that the vector is transposed.</p>
  
  <p>Now I am wondering a bit about the numpy dot function, because </p>
  
  <pre><code>returns = np.dot(expected_returns_annual, weights)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>returns = np.dot(expected_returns_annual, weights.T)
  </code></pre>
  
  <p>give the same results. </p>
  
  <p>I tested also the shape of weights.T and weights.</p>
  
  <pre><code>weights.shape
  Out[58]: (5,)
  weights.T.shape
  Out[59]: (5,)
  </code></pre>
  
  <p>The shape of weights.T should be (,5) and not (5,), but numpy displays them as equal (I also tried np.transpose, but there is the same result)</p>
  
  <p>Does anybody know why numpy behave this way? In my opinion the np.dot product automatically shape the vector the right why so that the vector product work well. Is that correct?</p>
  
  <p>Best regards
  Tom</p>