In [ ]:

```
import numpy as np
```

In [ ]:

```
id = lambda x: x.__array_interface__['data'][0]
```

In [ ]:

```
x = np.zeros(10); x.strides
```

In [ ]:

```
y = np.zeros((10, 10)); y.strides
```

`a`

, but with a different shape. The strides are such that this array looks like it is a vertically tiled version of `a`

. NumPy is *tricked*: it thinks `b`

is a 2D `n * n`

array with `n^2`

elements, whereas the data buffer really contains only `n`

elements.

In [ ]:

```
n = 1000; a = np.arange(n)
```

In [ ]:

```
b = np.lib.stride_tricks.as_strided(a, (n, n), (0, 4))
```

In [ ]:

```
b
```

In [ ]:

```
b.size, b.shape, b.nbytes
```

In [ ]:

```
%timeit b * b.T
```

`b`

and `b.T`

are arrays pointing to the same data buffer in memory, but with different strides.

In [ ]:

```
%timeit np.tile(a, (n, 1)) * np.tile(a[:, np.newaxis], (1, n))
```

You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).

IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).