def np_lst_sq_xval(vecMdl, aryFuncChnk, aryIdxTrn, aryIdxTst):
varNumXval = aryIdxTrn.shape[-<NUM_LIT:1>]<EOL>varNumVoxChnk = aryFuncChnk.shape[-<NUM_LIT:1>]<EOL>aryResXval = np.empty((varNumVoxChnk,<EOL>varNumXval),<EOL>dtype=np.float32)<EOL>for idxXval in range(varNumXval):<EOL><INDENT>vecMdlTrn = vecMdl[aryIdxTrn[:, idxXval], :]<EOL>vecMdlTst = vecMdl[aryIdxTst[:, idxXval], :]<EOL>aryFuncChnkTrn = aryFuncChnk[<EOL>aryIdxTrn[:, idxXval], :]<EOL>aryFuncChnkTst = aryFuncChnk[<EOL>aryIdxTst[:, idxXval], :]<EOL>vecTmpPe = np.linalg.lstsq(vecMdlTrn,<EOL>aryFuncChnkTrn,<EOL>rcond=-<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>aryMdlPrdTc = np.dot(vecMdlTst, vecTmpPe)<EOL>aryResXval[:, idxXval] = np.sum(<EOL>(np.subtract(aryFuncChnkTst,<EOL>aryMdlPrdTc))**<NUM_LIT:2>, axis=<NUM_LIT:0>)<EOL><DEDENT>return aryResXval<EOL>
Least squares fitting in numpy with cross-validation.