a={{0,1,2,2,0,0,1,0,3,3,3,0}, {0,0,0,1,1,0,0,0,2,0,0,0}, {2,0,0,1,5,4,1,2,5,0,0,0}}; (* 每列先根據元素0利用函數SplitBy分組,再把不包含0的子陣列取出並計算長度 *) Table[Map[Length,Select[SplitBy[a[[n]],#!=0&],FreeQ[#,0]==True&]], {n,Length@a}]
Copyright 2009 Engadget's Style - Design by FUNction, Ray Wei - Powered by Blogger
讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~