How to convert list of list to NumPy array

You can convert the list of lists to a NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.

# Import the NumPy library as np
import numpy as np

# Initialize a List of List
a = [[5, 10], [11, 7]]

# Convert list of list to NumPy array
b = np.array(a)

# Display the NumPy Array
print(b)

# Display the type
print(type(b))

Output:

[[ 5 10]
 [11  7]]
<class 'numpy.ndarray'>

Free Learning Resources

Leave a Comment

Your email address will not be published.