In [1]:
import numpy as np
import matplotlib.pyplot as plt

In [29]:
%matplotlib inline

plt.rcParams['figure.figsize'] = [12, 10]

In [3]:
def f(x, y):
    return (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)

In [4]:
n = 10
x = np.linspace(-3, 3, 3.5 * n)
y = np.linspace(-3, 3, 3.0 * n)
X, Y = np.meshgrid(x, y)

In [5]:
X


Out[5]:
array([[-3.        , -2.82352941, -2.64705882, ...,  2.64705882,
         2.82352941,  3.        ],
       [-3.        , -2.82352941, -2.64705882, ...,  2.64705882,
         2.82352941,  3.        ],
       [-3.        , -2.82352941, -2.64705882, ...,  2.64705882,
         2.82352941,  3.        ],
       ..., 
       [-3.        , -2.82352941, -2.64705882, ...,  2.64705882,
         2.82352941,  3.        ],
       [-3.        , -2.82352941, -2.64705882, ...,  2.64705882,
         2.82352941,  3.        ],
       [-3.        , -2.82352941, -2.64705882, ...,  2.64705882,
         2.82352941,  3.        ]])

In [6]:
len(x)


Out[6]:
35

In [7]:
len(X)


Out[7]:
30

In [8]:
len(Y)


Out[8]:
30

In [9]:
len(X[0])


Out[9]:
35

In [10]:
len(Y[0])


Out[10]:
35

In [11]:
Z = f(X, Y)

In [12]:
Z


Out[12]:
array([[ -4.07401958e-06,  -8.68446948e-06,  -1.72823048e-05, ...,
          1.14708330e-05,   6.47127721e-06,   3.28206063e-06],
       [ -1.32438750e-05,  -2.80571998e-05,  -5.53670988e-05, ...,
          3.99605633e-05,   2.21899038e-05,   1.11443477e-05],
       [ -3.96154755e-05,  -8.34588094e-05,  -1.63435942e-04, ...,
          1.26680044e-04,   6.94610008e-05,   3.46065615e-05],
       ..., 
       [ -3.42992238e-05,  -6.86021213e-05,  -1.24424770e-04, ...,
          1.65691215e-04,   8.43176888e-05,   3.99228131e-05],
       [ -1.10433613e-05,  -2.19076892e-05,  -3.92195151e-05, ...,
          5.61081471e-05,   2.83394144e-05,   1.33448614e-05],
       [ -3.25160068e-06,  -6.38615443e-06,  -1.12473149e-05, ...,
          1.75058230e-05,   8.76959225e-06,   4.10447954e-06]])

In [14]:
np.shape(Z)


Out[14]:
(30, 35)

In [15]:
import random

In [ ]:
x = r

In [16]:
plt.hist2d?

In [21]:
np.random.randn?

In [22]:
np.random.normal?

In [23]:
x = np.random.randn(1000)
y = np.random.randn(1000)

In [32]:
plt.hist2d(x, y, bins=40, cmap='jet', cmin=1)
plt.colorbar()


Out[32]:
<matplotlib.colorbar.Colorbar instance at 0x10993aea8>

In [33]:
np.random.multivariate_normal?

In [56]:
mean = [0, 0]
cov = [[1, 30], [30, 1000]]

x, y = np.random.multivariate_normal(mean, cov, 50000).T

In [57]:
plt.hist2d(x, y, bins=100, cmap='jet', cmin=1)
plt.colorbar()


Out[57]:
<matplotlib.colorbar.Colorbar instance at 0x10fa6e518>

In [ ]: