Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math.js access a single element in a matrix

It looks like a too basic job. However, I can't do it.

I added math.js to my HTML code

<script src="js/math.min.js"></script>

I define a matrix in firefox console:

var M = math.matrix([[1,0,0,4],[0,1,0,2],[0,5,1,9],[11,2,3,1]]);

So far everything is good.

M
Object { _data: Array[4], _size: Array[2], _datatype: undefined }

Now, I want to access a single element of the matrix:

M.index(1,2)

And I get an error

TypeError: M.index is not a function

like image 729
ar2015 Avatar asked May 06 '26 03:05

ar2015


1 Answers

It looks like you need to use math.index.

M.subset(math.index(1, 2));

But the preferred method, as pointed out by it's author, is using .get.

M.get([1, 2]);

As of the time of this writing, this feature is preferred but documentation is still catching up.

like image 95
Mike Cluck Avatar answered May 07 '26 17:05

Mike Cluck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!