[英]Python programming , calculate the class frequency
k=np.array(
[[1, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 1],
[1, 0, 1]]
)
In this array, how can I compute the frequency of each column For example: If I need positive case, the output should be [4,2,4] If I need negative case, the output should be [2,3,1]在这个数组中,如何计算每列的频率 例如:如果我需要正例,output 应该是 [4,2,4] 如果我需要负例,output 应该是 [2,3,1]
If it's just these two numeric symbols (meaning you can treat them as numbers).如果只是这两个数字符号(意味着您可以将它们视为数字)。
import numpy as np
k=np.array(
[[1, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 1],
[1, 0, 1]]
)
print(np.sum(k,axis=0))
print(np.sum(1-k,axis=0))
output: output:
[4 2 4] [4 2 4]
[1 3 1] [1 3 1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.