python统计数组中每个元素个数

import pandas as pd
import numpy as np

arr = np.random.random((2,3))    # 需要进行统计的数据
arr_gb = arr.flatten()           # 数组转为1维
arr_gb = pd.Series(arr_gb)       # 转换数据类型
arr_gb = arr_gb.value_counts()   # 计数
arr_gb.sort_index(inplace=True)  # 排序

结果如下:

python统计数组中每个元素个数_第1张图片

你可能感兴趣的:(python,python)