It is not possible to transfer the input array from form (3.1) to form (3,)

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) 

This is a qr factorization code, but I don't know why the error occurs. Value error occurs inV[k:m,k] = v

value error :
could not broadcast input array from shape (3,1) into shape (3) 
+4
source share
1 answer

V[k:m,k] = v; vhas the form (3.1), but the goal is (3). k:mis a 3-term slice; k- scalar.

Try to use v.ravel(). Or V[k:m,[k]].

But also understand why it vhas its form.

+8
source

Source: https://habr.com/ru/post/1656547/


All Articles