分割数组
我有一个逗号分隔值数组,例如 var myArray = [0,1,0,1,0,0,0,0,1]
我想根据计数拆分它(如果 count 为) 3 我想最终得到三个数组,就像
var myArrayA = [0,1,0];
var myArrayB = [1,0,0];
var myArrayC = [0,0,1];
我需要将其视为 3x3 矩阵并进行转置。
I have an array of comma separated values like var myArray = [0,1,0,1,0,0,0,0,1]
I want to split it based on a count if count is 3 I want to end up with three arrays like
var myArrayA = [0,1,0];
var myArrayB = [1,0,0];
var myArrayC = [0,0,1];
I need to treat it as a 3x3 matrix and do a transpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
array.slice 我的建议是
根据您的具体情况有一个看看这个
array.slice would be my suggestion
in your SPECIFIC situation have a look at this
尝试 array.slice(start, end)
示例:-
Try
array.slice(start, end)
Example:-
乐趣!
您真正需要知道的唯一一件事是,要转置,请为矩阵中的所有 (i,j) 设置 m(i,j) = m(j,i)。我最终转换为矩阵表示,它不太简洁但更易读......
Fun!
The only thing you need to know really is that to transpose, set m(i,j) = m(j,i) forall (i,j) in the matrix. I ended up converting to a matrix representation, which is less concise but mor legible...