Get Started with NumPy
Get Started
We need to import first the numpy library:
import numpy as np
Numpy - 1D array
list = [4,5,6,7,8,9]
# Creating a 1D array
np_array = np.array(list)
print(np_array) # Output: array([4,5,6,7,8,9])
# Example - Multiply per element
multiply_per_elelement = np_array * 2
print(multiply_per_elelement) #Output: [8 10 12 14 16 18]
Checking the data type using type()
function
Let's check what is the data type
type(np_array)
#output: numpy.ndarray
NumPy - 2D array
python_lists = [[1,2,3], [4,5,6], [7,8,9]]
print(np.array(python_lists)) # Output: array([[1,2,3], [4,5,6], [7,8,9]])