Numpy Data Science PDF
Document Details
Uploaded by JubilantMulberryTree
Shoolini University
Lokender Kumar Ph.D.
Tags
Summary
This document is a tutorial on Numpy and its application within Data Science. It provides information on creating and manipulating NumPy arrays, including zero arrays, ones arrays, identity matrices, and more. It also shows how to analyse NumPy arrays, including determining dimensions and array sizes.
Full Transcript
Foundation of Numpy Data Science Lokender Kumar Ph.D. Numpy NumPy - Numerical Python Advantages of Numpy Arrays: Allows several Mathematical Operations Faster operations Foundation of Data Science Lokender Kum...
Foundation of Numpy Data Science Lokender Kumar Ph.D. Numpy NumPy - Numerical Python Advantages of Numpy Arrays: Allows several Mathematical Operations Faster operations Foundation of Data Science Lokender Kumar Ph.D. Numpy import numpy as np from time import process_time Foundation of Data Science Lokender Kumar Ph.D. Numpy python_list = [i for i in range(10000)] start_time = process_time() python_list = [i+5 for i in python_list] end_time = process_time() print(end_time - start_time) Foundation of Data Science Lokender Kumar Ph.D. Functions np_array = np.array([i for i in range(10000)]) start_time = process_time() np_array += 5 end_time = process_time() print(end_time - start_time) Foundation of Data Science Lokender Kumar Ph.D. Functions # list list1 = [1,2,3,4,5] print(list1) type(list1) Foundation of Data Science Lokender Kumar Ph.D. Functions np_array = np.array([1,2,3,4,5]) print(np_array) type(np_array) Foundation of Data Science Lokender Kumar Ph.D. Functions # creating a 1 dim array a = np.array([1,2,3,4]) print(a) Foundation of Data Science Lokender Kumar Ph.D. Functions a.shape b = np.array([(1,2,3,4),(5,6,7,8)]) print(b) Foundation of Data Science Lokender Kumar Ph.D. Functions b.shape c = np.array([(1,2,3,4),(5,6,7,8)],dtype=float) print(c) Foundation of Data Science Lokender Kumar Ph.D. Functions Initial Placeholders in numpy arrays # create a numpy array of Zeros x = np.zeros((4,5)) print(x) # create a numpy array of ones y = np.ones((3,3)) print(y) Foundation of Data Science Lokender Kumar Ph.D. Functions Initial Placeholders in numpy arrays # array of a particular value z = np.full((5,4),5) print(z) # create an identity matrix a = np.eye(5) print(a) Foundation of Data Science Lokender Kumar Ph.D. Functions Initial Placeholders in numpy arrays # create a numpy array with random values b = np.random.random((3,4)) print(b) # random integer values array within a specific range c = np.random.randint(10,100,(3,5)) print(c) Foundation of Data Science Lokender Kumar Ph.D. Functions Initial Placeholders in numpy arrays # array of evenly spaced values --> specifying the number of values required d = np.linspace(10,30,5) print(d) # array of evenly spaced values --> specifying the step e = np.arange(10,30,5) print(e) Foundation of Data Science Lokender Kumar Ph.D. Functions Initial Placeholders in numpy arrays # convert a list to a numpy array list2 = [10,20,20,20,50] np_array = np.asarray(list2) print(np_array) type(np_array) Foundation of Data Science Lokender Kumar Ph.D. Functions Analysing a numpy array c = np.random.randint(10,90,(5,5)) print(c) # array dimension print(c.shape) # number of dimensions print(c.ndim) Foundation of Data Science Lokender Kumar Ph.D. Functions # number of elements in an array print(c.size) # checking the data type of the values in the array print(c.dtype) Foundation of Data Science Lokender Kumar Ph.D.