debajyotikarmaker / cvpr_4234

43 stars 65 forks source link

Quiz question : Converting the numpy array into list . #9

Open mhpranta12 opened 3 years ago

mhpranta12 commented 3 years ago

I think this is the way to convert numpy array into a list : import numpy as np

1d array to list

arr = np.array([1, 2, 3]) print(f'NumPy Array:\n{arr}')

list1 = arr.tolist() print(f'List: {list1}')

X-AVI-X commented 3 years ago

Actually you can convert numpy array to list by this also: list(array)

Here is an example:

import numpy as np
array = np.array([1, 2, 3])     //numpy array
print(type(array))
newlist = list (array)            //converted to list
print (type(newlist))

In output you will see the type of newlist is list image

So, the given answer was correct.

Ariful54 commented 3 years ago

We can use the built-in Python function list() to convert a numpy array into a list. The following is the syntax:

ls = list(arr)

Here, arr is a numpy array.