28 Mar 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:
1 2 3 4 5 6 7 |
import numpy as np n = np.array((1, 2, 3)) print(n) print(type(n)) |
Output
1 2 3 4 |
[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:
1 2 3 4 5 6 |
import numpy as np n = np.array([1, 2, 3]) print(type(n)) |
Output
1 2 3 |
<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:
No Comments