educative.io

Educative

What does it mean Inclusive and exclusive when talking about the range data arrays?

What does it mean Inclusive and exclusive when talking about the range data arrays ?

Hi @Frenchy,

Let’s take the example of the np.random.randint function.

  • If high=None:
    If high = None, then the random numbers will be in the range [0, n) which means that 0 is inclusive and n is exclusive. If n = 5, then the random integer is chosen uniformly from 0, 1, 2, 3, 4.
  • If high is not None
    Let’s say n = 5 and high = 10, then the random integer is chosen uniformly from the range [5, 10) i.e, 5 is inclusive, 10 is exclusive, and the random number is chosen uniformly from 5, 6, 7, 8, 9.

Now, let’s take the example of the np.random.uniform function. If low = 0.0 and high = 1.0, then the output will be in the range [0.0, 1.0). 0.0 will be inclusive but 1.0 will be exclusive, i.e, the output will never be 1.0.

Note: In the notation, “[“ means inclusive, and “)” means exclusive.

Best Regards,
Hiba Khurshid | Developer Advocate
educative.io

2 Likes