Numeric Python, popularly known as Numpy is a fundamental package for scientific computing with python. It is an opensource python library that provides an alternative to a regular Python list. It has very powerful N-dimensional arrays or data structures and routines to manipulate it. Numpy Array is similar to the python list but has additional features such as the ability to perform a calculation over entire arrays. It is really easy and super fast as well. It also has other derived objects like masked arrays and matrices. It can be used to performs various mathematical operations on arrays. It guarantees the efficient calculation with matrices and arrays and also provides high-level mathematical functions that can be operated to those arrays and matrices. They consume less memory and are convenient to use. Many times it is used by libraries like SciPy, matplotlib, OpenCv, Scikit-image, Scikit-learn, pandas to store multi-dimensional data.

To install NumPy in your device make sure you have already installed python and pip and then:

####
In the terminal: pip install NumPy

Now to actually use numpy in your program you first need to import it in the following ways:

####
Import numpy

Remember it all should be in a small letter. Whenever we use any functions from numpy we use it as below:

####
numpy.array

For Ease, you can import numpy as some name and use that name to call the function like below:

####
import numpy as np

np.array

Now lets initialize our first array first_array:

first_array = np.array([1, 2, 3, 4])

second_array = np.array( [5, 6, 7, 8])

you can also initialize matrices as follow:

first_matrix = np.array([[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8]])

we can access these elements as follow:

print(a[0])\

This will print [1, 2, 3, 4, 5, 6, 7, 8] for array of array.

Numpy has functions to automatically create arrays and matrices of 0's and 1's as follow:

Many functions can be performed between arrays and matrices like:

sort, concatenate, ndim, size, shape as follow:

>>> array_example = np.array([[[0, 1, 2, 3],
... [4, 5, 6, 7]],
...
... [[0, 1, 2, 3],
... [4, 5, 6, 7]],
...
... [[0 ,1 ,2, 3],
... [4, 5, 6, 7]]])

>>> array_example.ndim
3

>>> array_example.size
24

>>> array_example.shape
(3, 2, 4)

>>> np.concatenate((first_array, second_array))

array([1, 2, 3, 4, 5, 6, 7, 8])

>>> first_array.shape
(4,)

###
There are also functions to reshape the size of an array as follows:

>>> first_array = np.arange(6)
>>> print(first_array)
[0 1 2 3 4 5]

>>> second_array = first_array.reshape(3, 2)
>>> print(b)
[[0 1]
[2 3][4 5]]

###
Indexing and Slicing of an array can be performed in the following ways:

## Post a Comment