NumPy: Python Library for Data Science

Khushijain
Analytics Vidhya
Published in
3 min readJun 9, 2021
NumPy is a Python library used for working with arrays.

Importing the library

import numpy as np

Check version

 np.__version__

Create NumPy array from python list

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

Check type

type(arr)
# Output : <class 'numpy.ndarray'>
# arr is n-dimensional numpy array

Check datatype of elements in numpy array

arr.dtype
# Output : int64

Check dimension of numpy array

arr.ndim
# Output : 1
# arr is 1-dimensional array
np.array([[1,2],[3,4],[5,6]]).ndim
# Output : 2
# arr is 2-dimensional array

Check shape of numpy array

Changing the shape of numpy array

Reshape: Changing the shape of numpy array

Create an array in a range using ‘arange’

default np.arange(start=0, stop, step=1, dtype=‘int’)

‘linspace’

Returns evenly spaced samples over the interval [start, stop]

np.linspace(start=0, stop, nums=50, endpoint=True, retstep=False, dtype=None)

Statistics

Transpose

‘np.where’

argmin’ works with numpy array or lists

idxmin’ works only dataframes and series

drop_duplicates : Return DataFrame with duplicate rows removed.

To learn more about NumPy, check out the official documentation here.

In next blog we’ll discuss about another important library of python- ‘Pandas’ which makes working with dataset easy and is extensively use in Data Science.

Happy Learning!!

--

--