algorithm_globals.random_seed = 123456\n_ = torch.manual_seed(123456)\nnum_dim = 2\nnum_discrete_values = 8\nnum_qubits = num_dim * int(np.log2(num_discrete_values))\ncoords = np.linspace(-2, 2, num_discrete_values)\nrv = multivariate_normal(mean=[0.0, 0.0], cov=[[1, 0], [0, 1]], seed=algorithm_globals.random_seed)\ngrid_elements = np.transpose([np.tile(coords, len(coords)), np.repeat(coords, len(coords))])\nprob_data = rv.pdf(grid_elements)\nprob_data = prob_data / np.sum(prob_data)\nmesh_x, mesh_y = np.meshgrid(coords, coords)\ngrid_shape = (num_discrete_values, num_discrete_values)\n\nfig, ax = plt.subplots(figsize=(9, 9), subplot_kw={"projection": "3d"})\nprob_grid = np.reshape(prob_data, grid_shape)\nsurf = ax.plot_surface(mesh_x, mesh_y, prob_grid, cmap=cm.coolwarm, linewidth=0, antialiased=False)\nfig.colorbar(surf, shrink=0.5, aspect=5)\nplt.show()

使用 Python 生成二维网格并绘制正态分布概率图

原文地址: https://www.cveoy.top/t/topic/qzhq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录