如何在 ipython 中创建二维数组的直方图

How to create a histogram of 2D arrays in ipython

我已经使用随机数生成器创建了一个 1000*1000 的二维数组。我如何创建这些二维数组的直方图?

s1=np.random.rand(1000,1000)

安装并使用 matplotlib。您的代码将如下所示:

import matplotlib.pyplot as plt

s1=np.random.rand(1000,1000)
plt.hist(s1)

matplotlib 为您提供了大量有用的选项,您可以阅读更多关于它们的信息 here