我最近一直在尝试模拟一些 Monte Carlos 模拟并遇到了numpy.random. 检查指数生成器的文档我注意到这是页面中的警告,它告诉
Generator.exponential 应该用于新代码。
虽然如此,numpy.random.exponential仍然有效,但我无法运行Generator对应程序。我一直收到以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-c4cc7e61aa98> in <module>
----> 1 np.random.Generator.exponential(2, 1000)
TypeError: descriptor 'exponential' for 'numpy.random._generator.Generator' objects doesn't apply to a 'int' object
Run Code Online (Sandbox Code Playgroud)
我的问题是:
这2个有什么区别?
如何生成样本Generator?
我正在尝试在 Matplotlib 中使用偏移文本中的比例绘制 3D 图形。为此,我使用了ImportanceOfBeingErnest 的自定义轴主要格式化程序,以便将此比例设为乳胶格式:
\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\nfrom mpl_toolkits.mplot3d import Axes3D \nfrom matplotlib import cm\nimport numpy as np\n\nclass OOMFormatter(matplotlib.ticker.ScalarFormatter):\n def __init__(self, order=0, fformat="%1.1f", offset=True, mathText=True):\n self.oom = order\n self.fformat = fformat\n matplotlib.ticker.ScalarFormatter.__init__(self,useOffset=offset,useMathText=mathText)\n def _set_order_of_magnitude(self):\n self.orderOfMagnitude = self.oom\n def _set_format(self, vmin=None, vmax=None):\n self.format = self.fformat\n if self._useMathText:\n self.format = r\'$\\mathdefault{%s}$\' % self.format\n\n\nx = np.linspace(0, 22, 23)\ny = np.linspace(-10, 10, 21)\nX, Y = np.meshgrid(x, y)\nV = -(np.cos(X/10)*np.cos(Y/10))**2*1e-4\n\nfig, ax = plt.subplots(subplot_kw={"projection": "3d"})\nsurf = ax.plot_surface(X, …Run Code Online (Sandbox Code Playgroud)