Numpy is a Python library used in the Python programming language. Python list contains values corresponding to different data types whereas python arrays contain values corresponding to the same data types. It’s meant for creating Homogeneous n-dimensional arrays (n = 1….n).
Think about real-life Example: Daily life we will buy a big egg tray so these trays are considered to be homogenous because the size will be huge it's like 30 strawberries in a tray ..so think it arrays which have rows & columns. Here we cannot fit other food/flowers or veggies.
Installation of NumPy
As we know, Numpy is a Python library. To install NumPy, the system should have Python and Pip versions. I am using Kaggle Notebook to get started with the basics of Numpy.
NumPy arrays are faster and more compact than Python lists. An array consumes less memory and is convenient to use. NumPy uses much less memory to store data and it provides a mechanism of specifying the data types.
Example : a = np.array([1, 2, 3, 4, 5, 6]) Or
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
print(a[0])
[1,2,3,4]
Size comparison of Numpy Arrays :
In the above example
Numpy by default considers these integers as 8 bytes integers, however, we can give data types with Numpy arrays if we know the maximum range of the data.
For Example, We can use 1 Byte for storing integer for numbers up to 255 and 2 Bytes integer for numbers up to 65535.
Addition & Multiplication of Matrix :
np_arr1 = np.array([[1,2,3],[4,5,6]])
np_arr2 = np.array([[1,2,3],[4,5,6]])
np_arr3 = np_arr1*np_arr2
print (np_arr3);
np_arr4 = np_arr1+np_arr2
print (np_arr4);
output :
[[ 1,4, 9]
[ 16,25, 36]] #Matrix Multiplication
[2,4,6]
[8,10,12]]# Matrix Addition
But If we Take Uneven Matrix for calculation we can do Padding of 0’s & 1’s to empty spaces so we can get our matrix.
Hence these are the few Basic mathematical operations Numpy.
So Numpy Operations are easy to understand and Applying to mathematical calculations.
References for more information:
https://numpy.org/doc/stable/user/absolute_beginners.html https://www.geeksforgeeks.org/python-numpy/
If you like the Blog & found it helpful, please leave a clap!
Happy Reading! Thank you.