Python - NumPy

NumPy aka Numeric Python, a Python library to perform mathematical calculations on Arrays, Matrices etc

Installation: pip3 install numpy

Import NumPy: import numpy as np

Creating an NumPy array syntax: numpy_array_name = np.array(list_name)
For e.g., if there is Python list with name "height", the same list can be converted to NumPy Array with name "np_height" as shown here: np_height = np.array(height) 

NumPy arrays can contain "only one type" of data and each NumPy array will have it's own methods.
At times, even, if we give a different type of data, Python will implicitly the convert the type of Data.

Methods associated with a NumPy array can be seen using dir(numpy_array_name)

np.array([True, 1, 2]) + np.array([3, 4, False]) will give array([4, 5, 2])
Because "True is converted to 1, False is converted to 0." and 
Python represents this internally as np.array([4, 3, 0]) + np.array([0, 2, 2]) and will give array([4, 5, 2])

All operations like subsetting/indexing etc of lists will work with np.arrays

When we do "type(np.array)" on it will return "numpy.ndarray" meaning it is n dimensional array.
ndarray can be
  1. 1 dimension which means Vectors
  2. 2 dimension which means Matrices
  3. 3 dimensions or higher which means Tensors

NumPy was written in C language and it is to improve it's speed and execution of numerical calculations. 

Additional learning resources on NumPy


No comments:

Post a Comment