numjs icon indicating copy to clipboard operation
numjs copied to clipboard

multiply got error for different shape

Open RexHuang opened this issue 6 years ago • 0 comments

see my project: https://github.com/RexHuang/GaussNewton.js

I want to get result of following: Jf = nj.array([[1.3009595627444526,9.007230966684432],[1.6924957839670183,23.436086522021778],[2.201868575113508,45.734101316607926],[2.8645419789086186,79.33095528080969],[3.726653280367031,129.00795614214644],[4.848225222175984,201.4009610995515],[6.30734496560592,305.6835907468525],[8.205600748567576,454.4937036239815]]); Jf.T.multiply(Jf)

but got error: Uncaught Error: cwise: Arrays do not all have the same shape! at muleq_cwise_thunk (eval at n.exports (numjs.min.js:3), :8:71) at Object.muleq_ndarrayops [as muleq] (eval at o (numjs.min.js:3), :3:42) at T.multiply (numjs.min.js:3) at :2:6

I had use matrixjs to solve the problem, pls study from https://github.com/Airblader/matrixjs

Here's some of my implementation: // var delta = (Jf.T.multiply(Jf)).inv().multiply(Jf.T).multiply(r); var Mat_Jf=Jf.flatten().tolist().toMatrix(Jf.shape[0],Jf.shape[1]); var Mat_r=r.flatten().tolist().toMatrix(r.shape[0],r.shape[1]); var Mat_delta = Mat_Jf.transpose().multiply(Mat_Jf).inverse().multiply(Mat_Jf.transpose()).multiply(Mat_r); delta=nj.array(Mat_delta.toArray()).reshape(params.shape[0],params.shape[1]);

We also need the implement of inv() I like numjs, hope we can improve:)

RexHuang avatar Aug 20 '19 00:08 RexHuang