jquery怎么遍历二维数组
var arr = [[0,1],[2,3], [3,4]];$.each(arr, function(i, n){ $.each(n, function(j, m){ document.write(m); if(j < n.length - 1) document.write(","); }); document.write("< br />");});
结果:0,12,33,4
基本运算
1:转置矩阵
//其中A, B是m*n矩阵:
void tramat(matrix A,matrix B){ int i,j;
for(i=0; i<m; i++)
for(j=0;j<n;j++)
B[j]=A[j];
2:矩阵相加
//其中A,B,C是m*n矩阵:
void addmat(matrix C, matrix A, matrix B){
int i, j;
for(i=0; i<m; i++)
for(j=0;j<n;j++)
c[j] = A[j] + B[j];
3:矩阵相乘
//其中A是m*n矩阵,B是n*1矩阵,C为m*1矩阵
void mutmat(matrix C, matrix A, matrix B){
int i, j, k;
for(i=0; i<m; i++)
for(j=0; j<i; j++){
C[j]=0;
for(k=0; k<n; k++)
C[j] = C[j] + A[k] * B[k][j];
}
}
var arr = [[0,1],[2,3], [3,4]];
$.each(arr, function(i, n){
$.each(n, function(j, m){
document.write(m);
if(j < n.length - 1) document.write(",");
});
document.write("< br />");
});
结果:
0,1
2,3
3,4