👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.

Python cnvert np.array to list

In Python, there are two ways to convert a numpy array into list, with list() or tolist().


Let's take the following array as an example:

import numpy as np
myArray = np.array((1,2,3,4))


Functionnal: convert with list() :

# Convertto list: [1, 2, 3, 4]
myList = list(myArray)


Object-oriented: convert with .tolist() :

# Convertto list: [1, 2, 3, 4]
myList = myArray.tolist()

More