# dask.array.random.zipf

### dask.array.random.zipf(\*args, \*\*kwargs)

Draw samples from a Zipf distribution.

This docstring was copied from numpy.random.mtrand.RandomState.zipf.

Some inconsistencies with the Dask version may exist.

Samples are drawn from a Zipf distribution with specified parameter
a > 1.

The Zipf distribution (also known as the zeta distribution) is a
discrete probability distribution that satisfies Zipf’s law: the
frequency of an item is inversely proportional to its rank in a
frequency table.

#### NOTE
New code should use the ~numpy.random.Generator.zipf
method of a ~numpy.random.Generator instance instead;
please see the [Quick start](https://numpy.org/doc/stable/reference/random/index.html#random-quick-start).

* **Parameters:**
  **a**
  : Distribution parameter. Must be greater than 1.

  **size**
  : Output shape.  If the given shape is, e.g., `(m, n, k)`, then
    `m * n * k` samples are drawn.  If size is `None` (default),
    a single value is returned if `a` is a scalar. Otherwise,
    `np.array(a).size` samples are drawn.
* **Returns:**
  **out**
  : Drawn samples from the parameterized Zipf distribution.

#### SEE ALSO
[`scipy.stats.zipf`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.zipf.html#scipy.stats.zipf)
: probability density function, distribution, or cumulative density function, etc.

`random.Generator.zipf`
: which should be used for new code.

### Notes

The probability mass function (PMF) for the Zipf distribution is

$$
p(k) = \frac{k^{-a}}{\zeta(a)},

$$

for integers $k \geq 1$, where $\zeta$ is the Riemann Zeta
function.

It is named for the American linguist George Kingsley Zipf, who noted
that the frequency of any word in a sample of a language is inversely
proportional to its rank in the frequency table.

### References

### Examples

Draw samples from the distribution:

```pycon
>>> a = 4.0
>>> n = 20000
>>> s = np.random.zipf(a, n)
```

Display the histogram of the samples, along with
the expected histogram based on the probability
density function:

```pycon
>>> import matplotlib.pyplot as plt
>>> from scipy.special import zeta
```

bincount provides a fast histogram for small integers.

```pycon
>>> count = np.bincount(s)
>>> k = np.arange(1, s.max() + 1)
```

```pycon
>>> plt.bar(k, count[1:], alpha=0.5, label='sample count')
>>> plt.plot(k, n*(k**-a)/zeta(a), 'k.-', alpha=0.5,
...          label='expected count')
>>> plt.semilogy()
>>> plt.grid(alpha=0.4)
>>> plt.legend()
>>> plt.title(f'Zipf sample, a={a}, size={n}')
>>> plt.show()
```

<!-- !! processed by numpydoc !! -->
