0
0
NumPydata~30 mins

np.savez() for multiple arrays in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Save Multiple Arrays Using np.savez()
📖 Scenario: Imagine you are working with sensor data collected from different devices. Each device produces a list of measurements. You want to save all these lists into a single file so you can easily load them later for analysis.
🎯 Goal: You will create multiple NumPy arrays representing sensor data, then save them together into one file using np.savez(). Finally, you will print the names of the saved arrays to confirm the save was successful.
📋 What You'll Learn
Create three NumPy arrays with exact values
Create a filename variable to store the output file name
Use np.savez() to save all arrays into one file with specific names
Print the names of the saved arrays from the saved file
💡 Why This Matters
🌍 Real World
Saving multiple arrays in one file is useful when working with data from different sensors or experiments. It keeps data organized and easy to share.
💼 Career
Data scientists often save and load multiple datasets efficiently. Knowing how to use <code>np.savez()</code> helps manage data files in projects.
Progress0 / 4 steps
1
Create three NumPy arrays
Import NumPy as np. Create three arrays called sensor1, sensor2, and sensor3 with these exact values: sensor1 = np.array([10, 20, 30]), sensor2 = np.array([15, 25, 35]), sensor3 = np.array([12, 22, 32]).
NumPy
Need a hint?

Use np.array() to create each array with the exact numbers.

2
Create a filename variable
Create a variable called filename and set it to the string 'sensors_data.npz'.
NumPy
Need a hint?

Just assign the string 'sensors_data.npz' to the variable filename.

3
Save arrays into one file using np.savez()
Use np.savez() to save sensor1, sensor2, and sensor3 into the file named filename. Name the arrays inside the file as 's1', 's2', and 's3' respectively.
NumPy
Need a hint?

Use np.savez(filename, s1=sensor1, s2=sensor2, s3=sensor3) to save all arrays with names.

4
Load and print saved array names
Load the saved file using np.load(filename) as data. Then print the list of array names stored in data.files.
NumPy
Need a hint?

Use data = np.load(filename) and then print(list(data.files)) to see the saved array names.