python: could not broadcast input array from shape (3,1) into shape (3,)
<pre><code>import numpy as np
def qrhouse(A):
    (m,n) = A.shape
    R = A
    V = np.zeros((m,n))
    for k in range(0,min(m-1,n)):
        x = R[k:m,k]
        x.shape = (m-k,1)
        v = x + np.sin(x[0])*np.linalg.norm(x.T)*np.eye(m-k,1)
        V[k:m,k] = v
        R[k:m,k:n] = R[k:m,k:n]-(2*v)*(np.transpose(v)*R[k:m,k:n])/(np.transpose(v)*v)
    R = np.triu(R[0:n,0:n])     
    return V, R

A = np.array( [[1,1,2],[4,3,1],[1,6,6]] )
print qrhouse(A) 
</code></pre>

<p>It's qr factorization pytho code I don't know why error happens...
value error happens in <code>V[k:m,k] = v</code></p>

<pre><code>value error :
could not broadcast input array from shape (3,1) into shape (3) 
</code></pre>

<p>.</p>

<p><code>V[k:m,k] = v</code>; <code>v</code> has shape (3,1), but the target is (3,). <code>k:m</code> is a 3 term slice; <code>k</code> is a scalar.</p>

<p>Try using <code>v.ravel()</code>.  Or <code>V[k:m,[k]]</code>.  </p>

<p>But also understand why <code>v</code> has its shape.</p>

python numpy