w3resource

NumPy Interoperability Exercises, Practice, Solutions


This resource offers a total of 100 NumPy Interoperability problems for practice. It includes 20 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

The following exercises cover NumPy's interoperability with Python data structures (lists, tuples, dictionaries) and external libraries like Pandas. You'll practice converting between arrays, DataFrames, Series, CSV files, and nested lists, improving your ability to integrate NumPy with other data-handling tools.

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


1. List to Array Conversion

Write a NumPy program to convert a Python list to a NumPy array and print the array.

Click me to see the sample solution


2. Array to List Conversion

Write a NumPy program to convert a NumPy array to a native Python list and print the list.

Click me to see the sample solution


3. Tuple to Array Conversion

Write a NumPy program to convert a Python tuple to a NumPy array and print the array.

Click me to see the sample solution


4. Array to Tuple Conversion

Write a NumPy program to convert a NumPy array to a Python tuple and print the tuple.

Click me to see the sample solution


5. DataFrame to Array Conversion

Write a NumPy program to convert a Pandas DataFrame to a NumPy array and print the array.

Click me to see the sample solution


6. Array to DataFrame Conversion

Write a NumPy program to convert a NumPy array to a Pandas DataFrame and print the DataFrame.

Click me to see the sample solution


7. Dictionary to Array Conversion

Write a NumPy program to convert a dictionary with numeric values to a NumPy array and print the array.

Click me to see the sample solution


8. Array to Dictionary Conversion

Write a NumPy program to convert a NumPy array to a dictionary with indices as keys and array elements as values.

Click me to see the sample solution


9. Nested List to 2D Array Conversion

Write a NumPy program to convert a nested Python list to a 2D NumPy array and print the array.

Click me to see the sample solution


10. 2D Array to Nested List Conversion

Write a NumPy program to convert a 2D NumPy array to a nested Python list and print the list.

Click me to see the sample solution


11. Series to Array Conversion

Write a NumPy program to convert a Pandas Series to a NumPy array and print the array.

Click me to see the sample solution


12. Array to Series Conversion

Write a NumPy program to convert a NumPy array to a Pandas Series and print the Series.

Click me to see the sample solution


13. DataFrame Round-trip Conversion

Write a NumPy program to create a Pandas DataFrame, convert it to a NumPy array, and then convert it back to a DataFrame.

Click me to see the sample solution


14. Array to CSV Conversion

Write a NumPy program to save a NumPy array to a CSV file and verify the contents by reading the file.

Click me to see the sample solution


15. CSV to Array Conversion

Write a NumPy program to read a CSV file into a NumPy array and print the array.

Click me to see the sample solution


16. 3D Array to Nested List Conversion

Write a NumPy program to convert a 3D NumPy array to a list of lists of lists and print the result.

Click me to see the sample solution


17. Nested List to 3D Array Conversion

Write a NumPy program to convert a list of lists of lists to a 3D NumPy array and print the array.

Click me to see the sample solution


18. Mixed DataFrame to Array Conversion

Write a NumPy program to convert a Pandas DataFrame with mixed data types (numerics and strings) to a NumPy array.

Click me to see the sample solution


19. Array and DataFrame Combination

Write a NumPy program to combine a NumPy array and a Pandas DataFrame into a single DataFrame and print it.

Click me to see the sample solution


20. Array Append to List Conversion

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



Follow us on Facebook and Twitter for latest update.