Pre-recorded question

Question #270
In Python, how to convert a numpy.array into list?
Answer

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() :

# Convertit en liste : [1, 2, 3, 4]
myList = list(myArray)


Object-oriented: convert with .tolist() :

# Convertit en liste : [1, 2, 3, 4]
myList = myArray.tolist()

6 events in history
Answer by Alphonsio 10/20/2020 at 07:48:28 PM

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() :

# Convertit en liste : [1, 2, 3, 4]
myList = list(myArray)


Object-oriented: convert with .tolist() :

# Convertit en liste : [1, 2, 3, 4]
myList = myArray.tolist()

Answer by Alphonsio 10/20/2020 at 07:44:59 PM

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() :

# Convertit en liste : [1, 2, 3, 4]
myList = list(myArray)


Object-oriented: convert with .tolist() :

# Convertit en liste : [1, 2, 3, 4]
myList = myArray.tolist()

Answer by Alphonsio 10/20/2020 at 07:44:40 PM

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() :

# Convertit en liste : [1, 2, 3, 4]
myList = list(myArray)


Object-oriented: convert with .tolist() :

# Convertit en liste : [1, 2, 3, 4]
myList = myArray.tolist()

Answer by Alphonsio 10/20/2020 at 07:44:21 PM

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() :

# Convertit en liste : [1, 2, 3, 4]
myList = list(myArray)


Object-oriented: convert with .tolist() :

# Convertit en liste : [1, 2, 3, 4]
myList = myArray.tolist()




Answer by Alphonsio 10/20/2020 at 07:40:56 PM

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() :

# Convertit en liste : [1, 2, 3, 4]
myList = list(myArray)

Object-oriented: convert with .tolist() :

# Convertit en liste : [1, 2, 3, 4]
myList = myArray.tolist()




Question by Alphonsio 10/20/2020 at 07:37:59 PM
In Python, how to convert a numpy.array into list?
# ID Query URL Count

Icons proudly provided by Friconix.