Machine Learning Tutorial – Numpy

Python – Numpy

-Numpy is a python library designed for scientific calculation while working with datasets.
-It is originally developed by Travis Oliphant and later open-sourced under BSD-license
-First developed in the year 2006 and keep updating the library at regular intervals of time.
-Numpy is an abbreviation for Numerical Python

working with numpy
# installing numpy
pip install numpy

Code :

# importing numpy
    import numpy as np

1.Numpy ndarray
    data=[[2,4,5,3],[4,5,6,3]]
    data=np.array(data)
    print(data)

#print the shape of a data  
    print(data.shape)

#produce an array of all zeros
    print(np.zeros((2,3))

printing an array of all 1's
    print(np.ones(3,4)
#printing an array of 10 number
    array=np.arange(10)
    print(array)
#printing values in between array   
    print(array[2:5])

#making values zero  in an array
    array[5:8]=0
    print(array)

2. Array operation

#Arithmetic operation
    data=np.array([[5,5,6],[8,9,19]])
    print(data+5)

    or

    print(data-2)

    or

    print(data*data)
#Transpose of an array  
    data=np.arange(16).reshape((4,4))
    print(data)

    print(data.T)

#printing random values
    x=np.random.randn(2,3)
    print(x)

3.Statistical Methods
    #printing mean of random data   
    print(x.mean())

    #printing minimum data
    print(x.min())

    #printing maximum data
    print(x.max())

4.Matrix Class

        X=np.random.randn(3,2)
        X=np.matrix(X)

        Y==np.random.randn(2,2)
        Y=np.matrix(Y)

        print(X*Y)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top