Course Content
🎁 Bonus Modules (Integrated Throughout)
Data Analytics
What is NumPy?

NumPy stands for Numerical Python. It is a fundamental package used for numerical and scientific computing in Python.

 

  • It allows you to work with multidimensional arrays (matrices) efficiently.
  • NumPy provides a large library of mathematical functions that can operate on arrays directly.

 

To use it:

import numpy as np

NumPy Arrays

What is a NumPy Array?

  • A NumPy array is like a list, but with fixed size, same data type, and much faster computation.
  • It can be 1D, 2D, or even multi-dimensional.

 

Creating Arrays
a = np.array([1, 2, 3]) # 1D array
b = np.array([[1, 2], [3, 4]]) # 2D array

Array Attributes

  • a.shape → Returns the dimensions of the array
  • a.dtype → Data type of elements
  • a.ndim → Number of dimensions

Built-in Functions to Create Arrays
np.zeros((2,3)) # 2x3 array of zeros
np.ones((3,3)) # 3x3 array of ones
np.arange(0, 10, 2) # array([0, 2, 4, 6, 8])
np.linspace(1, 5, 5) # array([1., 2., 3., 4., 5.])

Math Functions in NumPy

NumPy has built-in vectorized operations, which means you don’t need to write loops to do math.

 

Basic Arithmetic
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

a + b # array([5, 7, 9])
a * b # array([ 4, 10, 18])


Universal Functions (ufuncs)

These functions apply element-wise on arrays

 

  • np.sqrt(a) → Square root
  • np.exp(a) → Exponential
  • np.log(a) → Natural logarithm
  • np.abs(a) → Absolute value
  • np.power(a, 2) → Power

Aggregation Functions

These functions help you summarize data:

 

  • np.sum(a) → Total sum
  • np.mean(a) → Average
  • np.median(a) → Middle value
  • np.std(a) → Standard deviation
  • np.max(a) / np.min(a) → Max and min

 

Example:

arr = np.array([[1, 2], [3, 4]])
np.sum(arr, axis=0) # sum column-wise → array([4, 6])
np.sum(arr, axis=1) # sum row-wise → array([3, 7])
Feature Benefit
Arrays Handle large datasets efficiently
Vectorization Perform math operations without loops
ufuncs Apply fast element-wise math functions
Aggregations Summarize and analyze data easily

Summary

 
  • NumPy arrays are fast and efficient containers for numerical data.
  • You can use NumPy to do everything from basic arithmetic to complex statistical calculations.
0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.