w3resource

NumPy I/O Operations: Exercises, Practice, and Solutions

NumPy I/O Operations Exercises [ 20 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a NumPy program that reads data from a CSV file into a NumPy array. The CSV file contains numeric data.
Click me to see the sample solution

2. Write a NumPy array with both numeric and string data to a CSV file.
Click me to see the sample solution

3. Write a NumPy program that reads data from a CSV file into a structured NumPy array with specified data types for each column.
Click me to see the sample solution

4. Write a structured NumPy array to a CSV file, ensuring proper formatting of different data types.
Click me to see the sample solution

5. Write a NumPy program that reads a CSV file containing missing values into a NumPy array, handling the missing values appropriately.
Click me to see the sample solution

6. Write a NumPy program that saves a NumPy array to a text file with space as the delimiter and then reads it back into a NumPy array.
Click me to see the sample solution

7. Write a NumPy array to a binary file using np.save and then load it back using np.load.
Click me to see the sample solution

8. Write a NumPy program that saves multiple NumPy arrays to a single binary file using np.savez and then loads them back using np.load.
Click me to see the sample solution

9. Write a NumPy array to an HDF5 file and then read it back into a NumPy array.
Click me to see the sample solution

10. Write a NumPy program that reads a specific dataset from an HDF5 file into a NumPy array.
Click me to see the sample solution

11. Write a NumPy program that saves a large NumPy array to a compressed .npz file and then reads it back into a NumPy array.
Click me to see the sample solution

12. Write a NumPy array to an Excel file using a library like pandas and then read it back into a NumPy array.
Click me to see the sample solution

13. Write a NumPy program that reads data from a JSON file into a NumPy array. The JSON file contains numeric data.
Click me to see the sample solution

14. Write a NumPy array with numeric data to a JSON file.
Click me to see the sample solution

15. Write a NumPy program that reads data from a CSV file into a Pandas DataFrame and then converts it to a NumPy array.
Click me to see the sample solution

16. Write a NumPy array to a SQLite database and then read it back into a NumPy array.
Click me to see the sample solution

17. Write a NumPy program that saves a NumPy array to a MATLAB .mat file using scipy.io.savemat and then reads it back using scipy.io.loadmat.
Click me to see the sample solution

18. Write a NumPy program that read image data from a PNG file into a NumPy array using an image processing library like PIL or opencv.
Click me to see the sample solution

19. Write a NumPy program that saves a NumPy array as an image file (e.g., PNG) using an image processing library like PIL or opencv.
Click me to see the sample solution

20. Write a NumPy program to append a NumPy array to a Python list and print the result.
Click me to see the sample solution

Python-Numpy Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/numpy/python-numpy-io-operations.php