This notebook was created by Jupyter AI with the following prompt:
/generate Create a Jupyter notebook that shows how to create a random array using numpy.
This Jupyter notebook demonstrates how to create a random array using the numpy library. The necessary libraries are imported and a random array is generated using the specified dimensions. The random seed is set to ensure reproducibility, and the generated random array is displayed.
import numpy as np
# Set the seed for reproducibility
np.random.seed(0)
# Generate a random array of shape (3, 4) with values between 0 and 1
random_array = np.random.rand(3, 4)
# Display the random array
random_array
array([[0.5488135 , 0.71518937, 0.60276338, 0.54488318], [0.4236548 , 0.64589411, 0.43758721, 0.891773 ], [0.96366276, 0.38344152, 0.79172504, 0.52889492]])
import numpy as np
# Specify the dimensions of the random array
rows = 5
columns = 3
# Create a random array with the specified dimensions
random_array = np.random.rand(rows, columns)
# Return the random array
random_array
array([[0.56804456, 0.92559664, 0.07103606], [0.0871293 , 0.0202184 , 0.83261985], [0.77815675, 0.87001215, 0.97861834], [0.79915856, 0.46147936, 0.78052918], [0.11827443, 0.63992102, 0.14335329]])
import numpy as np
np.random.seed(42)
import numpy as np
# Set the dimensions of the random array
rows = 5
cols = 3
# Create the random array
random_array = np.random.rand(rows, cols)
# Return the random array
random_array
array([[0.37454012, 0.95071431, 0.73199394], [0.59865848, 0.15601864, 0.15599452], [0.05808361, 0.86617615, 0.60111501], [0.70807258, 0.02058449, 0.96990985], [0.83244264, 0.21233911, 0.18182497]])
import numpy as np
random_array = np.random.random((3, 4))
random_array
array([[0.18340451, 0.30424224, 0.52475643, 0.43194502], [0.29122914, 0.61185289, 0.13949386, 0.29214465], [0.36636184, 0.45606998, 0.78517596, 0.19967378]])