![](/img/trans.png)
[英]Convert numpy array with values into array with frequency for each observation in each row
[英]Count frequency of each row in an array using Matlab
我有這個巨大的陣列。 我在一個單獨的數組中提取了唯一的行。 現在我想創建一個向量來存儲每個唯一行的出現。 我怎么能這樣做? 嘗試使用histc。 我發現了tabulate
,但只適用於矢量。
x=[62 29 64
63 32 61
63 32 61
63 32 61
63 31 62
62 29 64
62 29 64
65 29 60
62 29 64
63 32 61
63 32 61
63 29 62
63 32 61
62 29 64
];
uA=unique(x)
[row, count] = histc(x,unique(x,'rows'))
我得到以下錯誤: Edge vector must be monotonically non-decreasing.
在其他幾次嘗試中也遇到此錯誤。
以這種方式使用unique
-
[unique_rows,~,ind] = unique(x,'rows')
counts = histc(ind,unique(ind))
unqiue_rows
和counts
將是你可能會感興趣的輸出。
根據您提供的數據,它會產生 -
unique_rows =
62 29 64
63 29 62
63 31 62
63 32 61
65 29 60
counts =
5
1
1
6
1
優點:您可以提高通過避免第二次使用的性能unique
這樣-
counts = histc(ind,1:max(ind));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.