We are here to explore one of the basic package in python called Numpy. Without any mathematical computations, we could not infer any insights from the data, Hence we use Numpy package for the same.
As we can arrange our data into one-Dimensional, two-dimensional and so on. The 1D data are Vectors, 2D are Matrices and ND are as Tensors.
Here we will perform some operations on these 1D, 2D and nD form of data. These data can be stored in an data structure called array in different dimensions as said above. A high – level mathematical functions are written in this library, which can support the following:
- Powerful N-dimensional array object.
- Broadcasting functions.
- Tools for integrating C/C++ and Fortran code.
- Useful for computing linear algebra, Fourier transform, and random number capabilities.
Now, we will install numpy package using the command, “”pip install numpy“” which will install the numpy package successfully.
In order to use this package to our data, we need to import using the command
“import numpy as np“, np is an variable which will be used everywhere to access numpy package.
Creating Numpy Arrays

Here the numpy arrays are created using the variable np. Since it is an 2-Dim array, we created using 2 square brackets. [[]]
The type function, tells us the type of the array, whereas the shape function provide us the no.of rows and no.of columns in the array. The dtype gives us the datatype of the array values.
Now, we will explore some basic methods in numpy arrays which can be used for our analysis on the real world data.
arange() – arange method can be used to create array values, with the following 4 parameters.

start — starting the array from the start number. [0]
stop — end the array (excluded in stop value). [till 10]
step — jump the value. [jumps after 3 values]
dtype — the type of array or matrices [optional]
The syntax of the method is
np.arange(start=None, stop=None, step=None, dtype=None)
start = 0 stop = 10 step = 3
If you are not giving step value by default it will take value 1.
linspace() – Creates any size of the evenly spaced array or matrices between specified interval.
np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
np.linspace ( ) has 6 parameters :
- start — Starting value of the sequence
- stop — Last value of the sequence
- num — Number of samples to be generated
- endpoint — This is a boolean value. If the value of endpoint is true, then stop is the last sample of the sequence. The default value of endpoint is true.
- retstep — Default value is true. If the value of retstep is true then return samples and steps(the difference between 2 samples)
- dtype — The type of array or matrices
np.linspace(5., 10., 3) array([5., 7.5, 10]) ============================ start = 5. stop = 10. num = 3
reshape() – The main function of the numpy library is reshape() which is used to convert 1D array to nd matrices.

The important point to remember is that the multiplication of parameters equals to the no. of elements in the 1-Dimensional array.
np.arange(0, 10, 3) array([0, 3, 6, 9]) =================== Total numbers of array elements = 4
=========================================== np.arange(0, 10, 3).reshape(2, 2) array([[0, 3],[6, 9]]) ====================== Multiplication of reshape parameters = 4[2*2] ============================================
Total numbers of array element is equal to Multiplication of reshape parameters
zeros() – This method gives 0 values to the sample in the matrix.
np.zeros((2,3))
array([[0.,0.,0.,],
[0.,0.,0.,]])
ones() – np.ones( ) gives the 1 value to each sample in the matrix.

full() – It gives the constant samples to the matrix.

eye( ) – This method gives the identical matrix as a result. In the below example, it gives 2-Dimensional identical matrices.

random() – np.random( ) gives the random samples. The below example gives 2-Dimensional matrix of 2*3(number of rows = 2 and number of columns = 3) with random values.

We have reached the end of our blog, Hope you enjoyed reading my blog!.
Let’s explore pandas basics in the next blog. Comments are welcome 🙂
