Quiz on AI Interviews Prep Live Training Corporate Training

Introduction to NumPy

NumPy (Numerical Python) is a powerful Python library used for numerical computing. It provides support for arrays, matrices, and many mathematical functions to operate on these data structures efficiently.

Why Use NumPy?

  • Faster computations compared to Python lists
  • Efficient handling of large datasets
  • Support for multi-dimensional arrays
  • Widely used in Data Science, Machine Learning, and Scientific Computing

Installing NumPy

You can install NumPy using pip:

pip install numpy

Importing NumPy

import numpy as np

Creating NumPy Arrays


import numpy as np

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

Basic Operations


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

print(a + b)
print(a * b)
    

Advantages of NumPy Arrays

  • Consumes less memory
  • Faster execution
  • Easy mathematical operations