Instagram
youtube
Facebook
Twitter

Create a NumPy Array of Integers Between 5 and 15 with Shape (3, 5)

A Create a NumPy Array of Integers Between 5 and 15 with Shape (3, 5)

Short Description of the Program:
This program creates a 3x5 NumPy array filled with random integers between 5 and 14 using the np.random.randint() function.

Explanation:

  • import numpy as np
    Loads the NumPy library to use its functions.

     
  • np.random.randint(5, 15, size=(3, 5))
    Generates random integers where:

     
    • 5 is the inclusive lower bound.
       
    • 15 is the exclusive upper bound (i.e., values go up to 14).
       
    • size=(3, 5) creates a 3-row, 5-column 2D array.
       
  • print()
    Outputs the generated array.

Program:

import numpy as np

array_integers = np.random.randint(5, 15, size=(3, 5))

print("2D NumPy Array with Random Integers (5 to 14):\n", array_integers)