Create numpy arrays

To create Numpy arrays, use numpy.arrays() method in Python. We can create arrays by passing a tuple or list. Let’s see them one by one:

Create a Numpy array by passing tuple

The array() method is used in Numpy to create an array by passing a tuple:

import numpy as np

n = np.array((1, 2, 3))
print(n)
print(type(n))

Output

[1 2 3]
<class 'numpy.ndarray'>

Create a Numpy array by passing list

The array() method is used in Numpy to create an array by passing a list:

import numpy as np

n = np.array([1, 2, 3])
print(type(n))

Output

<class 'numpy.ndarray'>

Video Tutorial

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.

For Videos, Join Our YouTube Channel: Join Now


Read More:

Installing Numpy in PyCharm
Dimensions in Numpy Arrays
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment