我需要找到一種方法來計算從0到9出現在一個隨機矩陣中的每一數目多少次使用np.random.randint()
多少次的號碼出現在一個numpy的陣列
import numpy as np
p = int(input("Length of matrix: "))
m = np.random.randint(0,9,(p,p))
print(m)
創建例如,如果長度的矩陣= 4
- [[3 4 6 5] [3 4 4 3] [4 2 4 8] [6 8 2 7]]
多少次數4出現?它應該返回5.
首先,弄清楚你是怎麼做的。 –