这个问题该如何解决,求指点
bincount
python3
>>> import numpy as np
>>> a=np.random.randint(1,10,15).reshape(3,5)
>>> a
array([[4, 4, 1, 8, 4],
[7, 5, 8, 8, 1],
[5, 5, 1, 2, 7]])
>>> c=np.bincount(a.flat)
>>> c
array([0, 3, 1, 0, 3, 3, 0, 2, 3], dtype=int32)
>>> d=np.vstack((np.where(c>0), c[c>0]))
>>> d
array([[1, 2, 4, 5, 7, 8], # 值
[3, 1, 3, 3, 2, 3]], dtype=int32) # 个数
>>>
unique
>>> a=np.random.randint(1,10,15).reshape(3,5)/10
>>> a
array([[ 0.6, 0.8, 0.3, 0.5, 0.7],
[ 0.7, 0.6, 0.7, 0.4, 0.4],
[ 0.1, 0.8, 0.4, 0.5, 0.5]])
>>> 值,个数 = np.unique(a, return_counts=True)
>>> np.vstack((值, 个数))
array([[ 0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
[ 1. , 1. , 3. , 3. , 2. , 3. , 2. ]])
>>>
2 回答5.1k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1.3k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决