# NumPy Basics Operation & Function

## By-SANDEEP KUMAR PATEL

# What is NumPy?

NumPy is the fundamental package for scientific computing in Python. It is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more.

NumPy stands for ‘Numerical Python’. It is a package in Python to work with arrays. It is a basic scientific library. Its most important feature is the n-dimensional array object. It has uses in statistical functions, linear algebra, arithmetic operations, bitwise operations, etc.

We perform all the operations on the array elements. We can initialize these arrays in several ways.

# Prerequisite to Learn NumPy

The two basic prerequisites for NumPy are Python and Mathematics. We need to know the python basics to work with the NumPy module.

The functions available in NumPy are built on python language. We can hence combine the knowledge of python arrays and list for array initialization and operations.

# NumPy vs. Python arrays

The NumPy library is a great alternative to python arrays. The difference is that the NumPy arrays are homogeneous that makes it easier to work with. We can initialize the array elements in many ways, one being which is through the python lists.

The NumPy arrays are convenient as they have the following three features–

- Less Memory Requirement
- Faster Processing
- Convenience of use

# Uses of NumPy

NumPy is one of the most useful external libraries available in Python. It has a wide variety of functions to work with arrays and a powerful multi-dimensional array object. It has operations that are applicable to a vast range of platforms.

Numpy can be put to use for storing, manipulation, and deletion of array elements. We can use it for sorting, indexing, and stacking of the array elements. It has modules regarding various operations:

- Arithmetic operations
- Statistical Operations
- Bitwise Operators
- Linear Algebra
- Copying and viewing arrays
- Stacking
- Searching, Sorting, and counting, etc.
- Mathematical Operations
- Broadcasting
- Matplotlib for graphical representations
- Matrix Operations, etc.

# NumPy Installation

We can install Python NumPy by going to the command prompt and typing a simple command pip install NumPy. Then go to the IDE and use the import command import NumPy as np.

# The Basics

NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers. In NumPy dimensions are called *axes*.

For example, the coordinates of a point in 3D space `[1, 2, 1]`

has one axis. That axis has 3 elements in it, so we say it has a length of 3. In the example pictured below, the array has 2 axes. The first axis has a length of 2, the second axis has a length of 3.

**[[1.,** **0.,** **0.],**

**[0.,** **1.,** **2.]]**

NumPy’s array class is called `ndarray`

. It is also known by the alias `array`

. Note that `numpy.array`

is not the same as the Standard Python Library class `array.array`

, which only handles one-dimensional arrays and offers less functionality. The more important attributes of an `ndarray`

object are:

**ndarray.ndim**

the number of axes (dimensions) of the array.

**ndarray.shape**

the dimensions of the array. This is a tuple of integers indicating the size of the array in each dimension. For a matrix with *n* rows and *m* columns, `shape`

will be `(n,m)`

. The length of the `shape`

tuple is therefore the number of axes, `ndim`

.

**ndarray.size**

the total number of elements of the array. This is equal to the product of the elements of `shape`

.

**ndarray.dtype**

an object describing the type of the elements in the array. One can create or specify dtype’s using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples.

**ndarray.itemsize**

the size in bytes of each element of the array. For example, an array of elements of type `float64`

has `itemsize`

8 (=64/8), while one of type `complex32`

has `itemsize`

4 (=32/8). It is equivalent to `ndarray.dtype.itemsize`

.

**ndarray.data**

the buffer containing the actual elements of the array. Normally, we won’t need to use this attribute because we will access the elements in an array using indexing facilities

**Thank You For Your Time…..!!!**