全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1066 0
2013-02-26
Sometime I need to remove zeros in a covariance matrix in order to calculate eigenvalues of the sub-matrix.  Here is an utility to remove the corresponding rows and columns of zeros.

proc iml;
b={1 0 3 0 5,
   0 0 0 0 0,
   1 0 3 0 5,
   0 0 0 0 0,
   1 0 3 0 5}
   ;


start remove_rows_cols(a);
***a must be a square matrix**;
n=nrow(a);
nzero=ncol(loc(a[1:5]=0));
idx=loc(a=0);

return (shape(remove(a,idx),n-nzero,n-nzero));
finish;

c=remove_rows_cols(b);
print b c;


quit;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群