【发布时间】:2020-09-05 08:26:06
【问题描述】:
我刚开始使用 numpy..
得到下面的 np 表,并想计算每个单元格在列总数中的百分比。
data = np.array([[7,16,17], [12,11,3]])
headers = ["Grundskola", "Gymn", "Akademisk"]
# tabulate data
table = tabulate(data, headers, tablefmt="github")
# output
print(table)
| Grundskola | Gymn | Akademisk |
|--------------|--------|-------------|
| 7 | 16 | 17 |
| 12 | 11 | 3 |
到:
| Grundskola | Gymn | Akademisk |
|--------------|--------|-------------|
| 39%| 59% | 85% |
| 61%| 41% | 15% |
我知道 np.sum(data2, axis=0/1) 会给我总数,但我如何使用来计算数组。
数组的大小可以不同...
【问题讨论】:
标签: python python-3.x numpy percentage numpy-ndarray