Instagram
youtube
Facebook
Twitter

Create a NumPy Array of Random Values with Shape (4, 4)

A Create a NumPy Array of Random Values with Shape (4, 4)

Short Description of the Program:
This program generates a 4x4 NumPy array filled with random float values between 0 and 1 using the np.random.rand() function. Each time you run it, you’ll get a different set of random numbers.

Explanation:

  • import numpy as np
    Imports the NumPy library.

     
  • np.random.rand(4, 4)
    Generates a 2D array with 4 rows and 4 columns, filled with random values.
    Each value is a floating-point number in the range [0.0, 1.0).

     
  • print()
    Prints the generated random array on the screen.

     

Program:

import numpy as np

array_random = np.random.rand(4, 4)

print("2D NumPy Array with Random Values:\n", array_random)