DEV Community

TechPlygrnd
TechPlygrnd

Posted on

NumPy Tutorial #2: Creating Arrays

To create a numpy array, first you have to import the numpy library into your code

import numpy as np
Enter fullscreen mode Exit fullscreen mode

Then, use numpy array method to create the numpy array and pass a python list as its argument

list_of_number = [1, 2, 3, 4, 5]

arr = np.array(list_of_number)
Enter fullscreen mode Exit fullscreen mode

Not only you can pass a python list as the argument of array method, you can also pass a python tuple

tuple_of_number = (1, 2, 3, 4, 5)

arr = np.array(tuple_of_number)
Enter fullscreen mode Exit fullscreen mode

When you print the array,

print(arr)
Enter fullscreen mode Exit fullscreen mode

you will see the following output

[1 2 3 4 5]
Enter fullscreen mode Exit fullscreen mode

There you go, you have created a NumPy array. Thank you for reading this blog, and see you next time!

Top comments (0)