Introduction to Numpy Zipf Distribution

In This Article, You Will Learn About Numpy Zipf Distribution.

Numpy Zipf Distribution – Before moving ahead, let’s know a bit of Python Pareto Distribution.

Zipf distributions are used to show data samples based on Zipf law.

Zipf’s Law describes an algorithm for determining probability. Each frequency is the reciprocal its rank multiplied with the highest frequency.

It includes two parameters –

a – Parameter Distribution.

size - Shape of the returned array.

Example – Creating an array of random numbers of size 3×3 for Pareto distribution.

from numpy import random

z = random.zipf(a=2, size=(3, 3))

print(z)
Output - 

[[0.33157015 0.78567132 0.05616168]
 [1.49522206 0.25127247 0.27642687]
 [0.23563371 1.01420266 0.7143994 ]]

As shown above, it returned an array of shape 3×3 containing random numbers.

Note: Later you will learn more in our Python Zipf Distribution Tutorial.

Visualization of Zipf Distribution

Example – Creating 5000 points but visualizing only values < 25.

from numpy import random
import matplotlib.pyplot as plt
import seaborn as kl

x = random.zipf(a=2, size=5000)
kl.distplot(x[x < 25], kde=False)

plt.show()
numpy-zipf-distribution

As a result, it returned visualized Zipf Distribution graph.

If you find anything incorrect in the above-discussed topic and have any further questions, please comment below.

Like us on

Leave a Comment

Stay in the loop

codingstreets