admin管理员组文章数量:1310228
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
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
Share Improve this question asked Feb 12, 2016 at 23:15 ar2015ar2015 6,16010 gold badges61 silver badges119 bronze badgesTypeError: M.index is not a function
2 Answers
Reset to default 6It 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.
Apart from M.get([1, 2])
, you can also do -
var a = M._data; // a is a multidimensional array
console.log(a[1][2]);
本文标签: javascriptMathjs access a single element in a matrixStack Overflow
版权声明:本文标题:javascript - Math.js access a single element in a matrix - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741833450a2400072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论