Lecture on Numpy Functions

Jun 28, 2024

Lecture on Numpy Functions

Introduction

  • Previous topics covered: numpy slicing and various numpy functions
  • Agenda: demonstrating usage of Jupyter Notebook for numpy functions in this session

Setting Up Jupyter Notebook

  • Open Command Prompt as Administrator
  • Change directory using cd command
  • Launch Jupyter Notebook by typing jupyter notebook
  • Select or create a new notebook and rename it for simplicity

Numpy Basics

  • Import numpy as np using import numpy as np
  • Create a numpy array:
    arr1 = np.array([[1, 2, 3], [4, 5, 6]])
    

Axis in Numpy

  • axis=0: column-wise operations
  • axis=1: row-wise operations
  • Example: sum function
    arr1.sum(axis=0)  # Column wise sum
    arr1.sum(axis=1)  # Row wise sum
    

Dot Product

  • Dot product of two matrices requires compatible dimensions
  • Example and troubleshooting with Transpose function
    np.dot(arr1, arr2.T)  # Transpose second matrix
    
  • Search functionality for finding functions

Cross Product

  • Use np.cross for cross product of vectors
    np.cross(arr1, arr2)
    

Sorting in Numpy

  • Create numpy array and sort
    np.sort(arr1)
    np.sort(arr1, axis=0)  # Column-wise sort
    
  • Specifying sorting algorithm using kind parameter
    np.sort(arr1, kind='mergesort')
    
  • Available algorithms: 'quicksort', 'heapsort', 'mergesort'

Best Practices and Tips

  • Understanding numpy's reliance on precompiled C libraries
  • Memory allocation considerations while working with numpy
  • Keep updated with numpy documentation for latest changes and updates

Conclusion

  • Encouragement to share videos and subscribe to the channel
  • Upcoming topics: Data analysis techniques in numpy
  • Questionnaire on experience with numpy package