Instagram
youtube
Facebook
Twitter

Create a NumPy Array of Floating-Point Numbers Between 0 and 1 with Shape (2, 3, 4)

A Create a NumPy Array of Floating-Point Numbers Between 0 and 1 with Shape (2, 3, 4).

Short Description of the Program:
This program creates a 3-dimensional NumPy array of shape (2, 3, 4) filled with random floating-point numbers between 0 and 1 using np.random.rand().

Explanation:

  • import numpy as np
    Imports the NumPy library for numerical operations.

     
  • np.random.rand(2, 3, 4)
    Creates a 3D array with:

     
    • 2 blocks (depth)
       
    • Each block has 3 rows and 4 columns
       
    • All values are floating-point numbers between 0.0 and 1.0
       
  • print()
    Prints the generated 3D array.

Program:

import numpy as np

array_floats = np.random.rand(2, 3, 4)

print("3D NumPy Array with Random Floating-Point Numbers:\n", array_floats)