def nnls(A, b):
 (A, b) = map(asarray_chkfinite, (A, b))
 if (len(A.shape) != 2):
  raise ValueError('expected matrix')
 if (len(b.shape) != 1):
  raise ValueError('expected vector')
 (m, n) = A.shape
 if (m != b.shape[0]):
  raise ValueError('incompatible dimensions')
 w = zeros((n,), dtype=double)
 zz = zeros((m,), dtype=double)
 index = zeros((n,), dtype=int)
 (x, rnorm, mode) = _nnls.nnls(A, m, n, b, w, zz, index)
 if (mode != 1):
  raise RuntimeError('too many iterations')
 return (x, rnorm)

def nnls ( A , b ) : ( A , b ) = map ( asarray_chkfinite , ( A , b ) ) if ( len ( A . shape ) != 2 ) : raise ValueError ( 'expected matrix' ) if ( len ( b . shape ) != 1 ) : raise ValueError ( 'expected vector' ) ( m , n ) = A . shape if ( m != b . shape [ 0 ] ) : raise ValueError ( 'incompatible dimensions' ) w = zeros ( ( n , ) , dtype = double ) zz = zeros ( ( m , ) , dtype = double ) index = zeros ( ( n , ) , dtype = int ) ( x , rnorm , mode ) = _nnls . nnls ( A , m , n , b , w , zz , index ) if ( mode != 1 ) : raise RuntimeError ( 'too many iterations' ) return ( x , rnorm )
solve argmin_x || ax - b ||_2 for x>=0 .