0
0
NumPydata~10 mins

np.ones() for one-filled arrays in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Create and Use One-Filled Arrays with np.ones()
📖 Scenario: Imagine you are helping a factory manager who wants to track the status of machines. Each machine is either working (1) or not working (0). To start, the manager wants to create a list showing all machines are working.
🎯 Goal: You will create a one-filled array using np.ones() to represent all machines working. Then, you will set a threshold for the number of machines and finally print the array.
📋 What You'll Learn
Create a numpy array of ones with a specific size
Create a variable to hold the number of machines
Use np.ones() with the number of machines
Print the resulting array
💡 Why This Matters
🌍 Real World
One-filled arrays are useful to represent active or working states in machines, sensors, or other systems.
💼 Career
Data scientists often initialize arrays with ones to set default values or masks before processing data.
Progress0 / 4 steps
1
Create a numpy array of ones
Import numpy as np and create a numpy array called machines filled with ones of size 5 using np.ones().
NumPy
Need a hint?

Use np.ones(5) to create an array of five ones.

2
Set the number of machines
Create a variable called num_machines and set it to 5.
NumPy
Need a hint?

Just write num_machines = 5.

3
Create the one-filled array using the variable
Update the machines array to use np.ones() with the size from num_machines.
NumPy
Need a hint?

Use the variable num_machines inside np.ones().

4
Print the one-filled array
Print the machines array to show the one-filled array.
NumPy
Need a hint?

Use print(machines) to display the array.