w3resource

NumPy: Convert a given array into a list and then convert it into a list again

NumPy: Basic Exercise-39 with Solution

Write a NumPy program to convert a given array into a list and then convert it into a list again.

Sample Solution :

Python Code :

import numpy as np
a = [[1, 2], [3, 4]]
x = np.array(a)
a2 = x.tolist()
print(a == a2)

Sample Output:

True                         

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to convert a given array into bytes, and load it as array.
Next: Write a NumPy program to compute the x and y coordinates for points on a sine curve and plot the points using matplotlib.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Python: The Zip() Function

>>> students = ('John', 'Mary', 'Mike')
>>> ages = (15, 17, 16)
>>> scores = (90, 88, 82, 17, 14)
>>> for student, age, score in zip(students, ages, scores):
...     print(f'{student}, age: {age}, score: {score}')
... 
John, age: 15, score: 90
Mary, age: 17, score: 88
Mike, age: 16, score: 82
>>> zipped = zip(students, ages, scores)
>>> a, b, c = zip(*zipped)
>>> print(b)
(15, 17, 16)