0
0
NumPydata~15 mins

Uniform random with random() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Uniform random numbers with numpy.random.random()
📖 Scenario: Imagine you are helping a game developer create random positions for objects in a 2D game world. The positions should be random numbers between 0 and 1, representing coordinates inside the game screen.
🎯 Goal: You will create a list of random numbers using numpy.random.random() to simulate these random positions.
📋 What You'll Learn
Use numpy to generate random numbers
Create an array of 5 random numbers between 0 and 1
Store the random numbers in a variable called positions
Print the positions array
💡 Why This Matters
🌍 Real World
Random numbers are used in games, simulations, and data sampling to create unpredictable results.
💼 Career
Data scientists often generate random samples to test models or simulate data.
Progress0 / 4 steps
1
Import numpy and create an empty array
Import the numpy library as np. Then create an empty variable called positions and set it to None.
NumPy
Need a hint?

Use import numpy as np to import numpy. Initialize positions with None for now.

2
Generate 5 uniform random numbers
Use np.random.random() with the argument 5 to generate an array of 5 random numbers between 0 and 1. Assign this array to the variable positions.
NumPy
Need a hint?

Call np.random.random(5) to get 5 random floats between 0 and 1.

3
Check the type and shape of positions
Use type(positions) and positions.shape to check the type and shape of the positions array. Store the type in a variable called pos_type and the shape in a variable called pos_shape.
NumPy
Need a hint?

Use type(positions) and positions.shape to get the type and shape.

4
Print the positions array
Print the positions array to see the 5 random numbers.
NumPy
Need a hint?

Use print(positions) to display the array.