| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 | import numpy as np
 
 from scipy.stats import mode
 
 a = np.array([[2, 2, 2, 1],
 [1, 2, 2, 2],
 [1, 1, 3, 3]])
 print("# Print mode(a):", mode(a))
 print("# Print mode(a.transpose()):", mode(a.transpose()))
 print("# a的每一列中最常见的成员为:{},分别出现了{}次。".format(mode(a)[0][0], mode(a)[1][0]))
 print("# a的第一列中最常见的成员为:{},出现了{}次。".format(mode(a)[0][0][0], mode(a)[1][0][0]))
 print("# a的每一行中最常见的成员为:{},分别出现了{}次。".format(mode(a.transpose())[0][0], mode(a.transpose())[1][0]))
 print("# a中最常见的成员为:{},出现了{}次。".format(mode(a.reshape(-1))[0][0], mode(a.reshape(-1))[1][0]))
 
 
 
 
 
 
 
 |